Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
use JavaScriptDialogManager for window dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
bridiver committed Dec 2, 2016
1 parent cedf446 commit 072e85f
Show file tree
Hide file tree
Showing 11 changed files with 518 additions and 73 deletions.
2 changes: 0 additions & 2 deletions atom/atom_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
<include name="IDR_ATOM_EVENT_EMITTER_JS" file="common\api\resources\event_emitter.js" type="BINDATA" />
<include name="IDR_ATOM_IPC_INTERNAL_JS" file="common\api\resources\ipc_utils.js" type="BINDATA" />

<include name="IDR_ATOM_IPC_WINDOW_DIALOGS_JS" file="common\api\resources\ipc_bindings.js" type="BINDATA" />

<include name="IDR_ATOM_PRIVACY_BINDINGS_JS" file="common\api\resources\privacy_bindings.js" type="BINDATA" />

<include name="IDR_ATOM_TABS_BINDINGS_JS" file="common\api\resources\tabs_bindings.js" type="BINDATA" />
Expand Down
7 changes: 7 additions & 0 deletions atom/browser/api/atom_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,16 @@ void WebContents::AddNewContents(content::WebContents* source,
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());

auto source_api_contents = CreateFrom(isolate(), source);
auto new_api_contents = CreateFrom(isolate(), new_contents);

if (source_api_contents->GetType() == BACKGROUND_PAGE) {
user_gesture = true;
}

std::unique_ptr<base::DictionaryValue> options(new base::DictionaryValue);
options->SetString("openerUrl", source_api_contents->GetURL().spec());
options->SetInteger("openerTabId", source_api_contents->GetID());
options->SetBoolean("userGesture", user_gesture);

auto url_params = new_api_contents->delayed_load_url_params_.get();
Expand Down
7 changes: 2 additions & 5 deletions atom/browser/common_web_contents_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <vector>

#include "atom/browser/atom_browser_context.h"
#include "atom/browser/atom_javascript_dialog_manager.h"
#include "atom/browser/atom_security_state_model_client.h"
#include "atom/browser/browser.h"
#include "atom/browser/native_window.h"
Expand All @@ -19,6 +18,7 @@
#include "atom/common/atom_constants.h"
#include "base/files/file_util.h"
#include "base/strings/utf_string_conversions.h"
#include "brave/browser/brave_javascript_dialog_manager.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
#include "chrome/browser/printing/print_preview_message_handler.h"
Expand Down Expand Up @@ -427,10 +427,7 @@ bool CommonWebContentsDelegate::CanOverscrollContent() const {
content::JavaScriptDialogManager*
CommonWebContentsDelegate::GetJavaScriptDialogManager(
content::WebContents* source) {
if (!dialog_manager_)
dialog_manager_.reset(new AtomJavaScriptDialogManager);

return dialog_manager_.get();
return brave::BraveJavaScriptDialogManager::GetInstance();
}

content::ColorChooser* CommonWebContentsDelegate::OpenColorChooser(
Expand Down
2 changes: 0 additions & 2 deletions atom/browser/common_web_contents_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ using brightray::DevToolsFileSystemIndexer;
namespace atom {

class AtomBrowserContext;
class AtomJavaScriptDialogManager;
class NativeWindow;
class WebDialogHelper;

Expand Down Expand Up @@ -163,7 +162,6 @@ class CommonWebContentsDelegate
bool native_fullscreen_;

std::unique_ptr<WebDialogHelper> web_dialog_helper_;
std::unique_ptr<AtomJavaScriptDialogManager> dialog_manager_;
scoped_refptr<DevToolsFileSystemIndexer> devtools_file_system_indexer_;

// Make sure BrowserContext is alwasys destroyed after WebContents.
Expand Down
5 changes: 3 additions & 2 deletions atom/common/api/event_emitter_caller.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <vector>

#include "gin/converter.h"
#include "native_mate/converter.h"

namespace mate {
Expand All @@ -28,7 +29,7 @@ v8::Local<v8::Value> EmitEvent(v8::Isolate* isolate,
v8::Local<v8::Object> obj,
const StringType& name,
const internal::ValueVector& args) {
internal::ValueVector concatenated_args = { StringToV8(isolate, name) };
internal::ValueVector concatenated_args = { gin::StringToV8(isolate, name) };
concatenated_args.reserve(1 + args.size());
concatenated_args.insert(concatenated_args.end(), args.begin(), args.end());
return internal::CallEmitWithArgs(isolate, obj, &concatenated_args);
Expand All @@ -42,7 +43,7 @@ v8::Local<v8::Value> EmitEvent(v8::Isolate* isolate,
const StringType& name,
const Args&... args) {
internal::ValueVector converted_args = {
StringToV8(isolate, name),
gin::StringToV8(isolate, name),
ConvertToV8(isolate, args)...,
};
return internal::CallEmitWithArgs(isolate, obj, &converted_args);
Expand Down
33 changes: 0 additions & 33 deletions atom/common/api/resources/ipc_bindings.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ void AtomExtensionsDispatcherDelegate::PopulateSourceMap(
source_map->RegisterSource("event_emitter", IDR_ATOM_EVENT_EMITTER_JS);
source_map->RegisterSource("ipcRenderer", IDR_BRAVE_IPC_RENDERER_JS);
source_map->RegisterSource("ipc_utils", IDR_ATOM_IPC_INTERNAL_JS);
source_map->RegisterSource("windowDialogs", IDR_ATOM_IPC_WINDOW_DIALOGS_JS);
source_map->RegisterSource("webFrame",
IDR_ATOM_WEB_FRAME_BINDINGS_JS);
source_map->RegisterSource("remote",
Expand Down
28 changes: 0 additions & 28 deletions atom/renderer/extensions/atom_extensions_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,6 @@ bool IsStandaloneExtensionProcess() {
extensions::switches::kExtensionProcess);
}

void DidCreateDocumentElement(content::RenderFrame* render_frame) {
v8::Isolate* isolate = blink::mainThreadIsolate();
v8::HandleScope handle_scope(isolate);

v8::Local<v8::Context> context =
render_frame->GetWebFrame()->mainWorldScriptContext();
v8::Context::Scope context_scope(context);

auto script_context =
extensions::ScriptContextSet::GetContextByV8Context(context);

if (script_context) {
extensions::ModuleSystem::NativesEnabledScope
natives_enabled(script_context->module_system());
script_context->module_system()
->CallModuleMethod("windowDialogs", "didCreateDocumentElement");
}

// reschedule the callback because a new render frame
// is not always created when navigating
extensions::ExtensionFrameHelper::Get(render_frame)
->ScheduleAtDocumentStart(base::Bind(DidCreateDocumentElement,
render_frame));
}

} // namespace

namespace extensions {
Expand Down Expand Up @@ -127,9 +102,6 @@ void AtomExtensionsRendererClient::RenderFrameCreated(
new extensions::ExtensionFrameHelper(render_frame,
extension_dispatcher_.get());
extension_dispatcher_->OnRenderFrameCreated(render_frame);
ExtensionFrameHelper::Get(render_frame)
->ScheduleAtDocumentStart(base::Bind(DidCreateDocumentElement,
render_frame));
}

void AtomExtensionsRendererClient::RenderViewCreated(
Expand Down
2 changes: 2 additions & 0 deletions brave/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ source_set("browser") {
"brave_browser_context.cc",
"brave_content_browser_client.h",
"brave_content_browser_client.cc",
"brave_javascript_dialog_manager.h",
"brave_javascript_dialog_manager.cc",
"brave_permission_manager.h",
"brave_permission_manager.cc",
"renderer_preferences_helper.h",
Expand Down
Loading

0 comments on commit 072e85f

Please sign in to comment.