diff options
20 files changed, 102 insertions, 60 deletions
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index f2a6ab4..ebcc8ed 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -701,6 +701,7 @@ static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) { void ChromeContentBrowserClient::GuestWebContentsCreated( WebContents* guest_web_contents, WebContents* opener_web_contents, + content::BrowserPluginGuestDelegate** guest_delegate, scoped_ptr<base::DictionaryValue> extra_params) { if (opener_web_contents) { GuestView* guest = GuestView::FromWebContents(opener_web_contents); @@ -711,11 +712,11 @@ void ChromeContentBrowserClient::GuestWebContentsCreated( switch (guest->GetViewType()) { case GuestView::WEBVIEW: { - new WebViewGuest(guest_web_contents); + *guest_delegate = new WebViewGuest(guest_web_contents); break; } case GuestView::ADVIEW: { - new AdViewGuest(guest_web_contents); + *guest_delegate = new AdViewGuest(guest_web_contents); break; } default: @@ -733,9 +734,9 @@ void ChromeContentBrowserClient::GuestWebContentsCreated( extra_params->GetString(guestview::kAttributeApi, &api_type); if (api_type == "adview") { - new AdViewGuest(guest_web_contents); + *guest_delegate = new AdViewGuest(guest_web_contents); } else if (api_type == "webview") { - new WebViewGuest(guest_web_contents); + *guest_delegate = new WebViewGuest(guest_web_contents); } else { NOTREACHED(); } diff --git a/chrome/browser/chrome_content_browser_client.h b/chrome/browser/chrome_content_browser_client.h index 0996c6e..9d93ddd 100644 --- a/chrome/browser/chrome_content_browser_client.h +++ b/chrome/browser/chrome_content_browser_client.h @@ -62,6 +62,7 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient { virtual void GuestWebContentsCreated( content::WebContents* guest_web_contents, content::WebContents* opener_web_contents, + content::BrowserPluginGuestDelegate** guest_delegate, scoped_ptr<base::DictionaryValue> extra_params) OVERRIDE; virtual void GuestWebContentsAttached( content::WebContents* guest_web_contents, diff --git a/chrome/browser/guestview/adview/adview_guest.cc b/chrome/browser/guestview/adview/adview_guest.cc index 1f20a21..a882d5f 100644 --- a/chrome/browser/guestview/adview/adview_guest.cc +++ b/chrome/browser/guestview/adview/adview_guest.cc @@ -50,7 +50,3 @@ void AdViewGuest::DidCommitProvisionalLoadForFrame( args->SetBoolean(guestview::kIsTopLevel, is_main_frame); DispatchEvent(new GuestView::Event(adview::kEventLoadCommit, args.Pass())); } - -void AdViewGuest::WebContentsDestroyed(WebContents* web_contents) { - delete this; -} diff --git a/chrome/browser/guestview/adview/adview_guest.h b/chrome/browser/guestview/adview/adview_guest.h index 35db3c3..5b40e31 100644 --- a/chrome/browser/guestview/adview/adview_guest.h +++ b/chrome/browser/guestview/adview/adview_guest.h @@ -37,8 +37,6 @@ class AdViewGuest : public GuestView, const GURL& url, content::PageTransition transition_type, content::RenderViewHost* render_view_host) OVERRIDE; - virtual void WebContentsDestroyed( - content::WebContents* web_contents) OVERRIDE; DISALLOW_COPY_AND_ASSIGN(AdViewGuest); }; diff --git a/chrome/browser/guestview/guestview.h b/chrome/browser/guestview/guestview.h index 4a0570b..09b01b5 100644 --- a/chrome/browser/guestview/guestview.h +++ b/chrome/browser/guestview/guestview.h @@ -8,6 +8,7 @@ #include <queue> #include "base/values.h" +#include "content/public/browser/browser_plugin_guest_delegate.h" #include "content/public/browser/web_contents.h" class AdViewGuest; @@ -17,7 +18,7 @@ class WebViewGuest; // tag. GuestView maintains an association between a guest WebContents and an // embedder WebContents. It receives events issued from the guest and relays // them to the embedder. -class GuestView { +class GuestView : public content::BrowserPluginGuestDelegate { public: enum Type { WEBVIEW, diff --git a/chrome/browser/guestview/webview/webview_constants.cc b/chrome/browser/guestview/webview/webview_constants.cc index dd4c8f4..2b4cc64 100644 --- a/chrome/browser/guestview/webview/webview_constants.cc +++ b/chrome/browser/guestview/webview/webview_constants.cc @@ -7,12 +7,19 @@ namespace webview { // Events. +const char kEventConsoleMessage[] = "webview.onConsoleMessage"; const char kEventContentLoad[] = "webview.onContentLoad"; const char kEventLoadCommit[] = "webview.onLoadCommit"; const char kEventLoadRedirect[] = "webview.onLoadRedirect"; const char kEventLoadStart[] = "webview.onLoadStart"; const char kEventLoadStop[] = "webview.onLoadStop"; +// Parameters/properties on events. +const char kLevel[] = "level"; +const char kMessage[] = "message"; +const char kLine[] = "line"; +const char kSourceId[] = "sourceId"; + // Internal parameters/properties on events. const char kInternalCurrentEntryIndex[] = "currentEntryIndex"; const char kInternalEntryCount[] = "entryCount"; diff --git a/chrome/browser/guestview/webview/webview_constants.h b/chrome/browser/guestview/webview/webview_constants.h index 01cec96..a9d5c7c 100644 --- a/chrome/browser/guestview/webview/webview_constants.h +++ b/chrome/browser/guestview/webview/webview_constants.h @@ -10,12 +10,19 @@ namespace webview { // Events. +extern const char kEventConsoleMessage[]; extern const char kEventContentLoad[]; extern const char kEventLoadCommit[]; extern const char kEventLoadRedirect[]; extern const char kEventLoadStart[]; extern const char kEventLoadStop[]; +// Parameters/properties on events. +extern const char kLevel[]; +extern const char kMessage[]; +extern const char kLine[]; +extern const char kSourceId[]; + // Internal parameters/properties on events. extern const char kInternalCurrentEntryIndex[]; extern const char kInternalEntryCount[]; diff --git a/chrome/browser/guestview/webview/webview_guest.cc b/chrome/browser/guestview/webview/webview_guest.cc index 5c15a6f..1ffcd37 100644 --- a/chrome/browser/guestview/webview/webview_guest.cc +++ b/chrome/browser/guestview/webview/webview_guest.cc @@ -78,6 +78,20 @@ AdViewGuest* WebViewGuest::AsAdView() { return NULL; } +void WebViewGuest::AddMessageToConsole(int32 level, + const string16& message, + int32 line_no, + const string16& source_id) { + scoped_ptr<DictionaryValue> args(new DictionaryValue()); + // Log levels are from base/logging.h: LogSeverity. + args->SetInteger(webview::kLevel, level); + args->SetString(webview::kMessage, message); + args->SetInteger(webview::kLine, line_no); + args->SetString(webview::kSourceId, source_id); + DispatchEvent( + new GuestView::Event(webview::kEventConsoleMessage, args.Pass())); +} + void WebViewGuest::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { @@ -161,7 +175,6 @@ void WebViewGuest::WebContentsDestroyed(WebContents* web_contents) { browser_context(), extension_id(), embedder_render_process_id(), view_instance_id())); - delete this; } void WebViewGuest::LoadHandlerCalled() { diff --git a/chrome/browser/guestview/webview/webview_guest.h b/chrome/browser/guestview/webview/webview_guest.h index 905d346..5baa3d9 100644 --- a/chrome/browser/guestview/webview/webview_guest.h +++ b/chrome/browser/guestview/webview/webview_guest.h @@ -39,6 +39,12 @@ class WebViewGuest : public GuestView, virtual WebViewGuest* AsWebView() OVERRIDE; virtual AdViewGuest* AsAdView() OVERRIDE; + // GuestDelegate implementation. + virtual void AddMessageToConsole(int32 level, + const string16& message, + int32 line_no, + const string16& source_id) OVERRIDE; + // NotificationObserver implementation. virtual void Observe(int type, const content::NotificationSource& source, diff --git a/chrome/renderer/resources/extensions/web_view.js b/chrome/renderer/resources/extensions/web_view.js index ee95690..68aa908 100644 --- a/chrome/renderer/resources/extensions/web_view.js +++ b/chrome/renderer/resources/extensions/web_view.js @@ -25,7 +25,6 @@ var WEB_VIEW_API_METHODS = [ var WEB_VIEW_EVENTS = { 'close': [], - 'consolemessage': ['level', 'message', 'line', 'sourceId'], 'exit' : ['processId', 'reason'], 'loadabort' : ['url', 'isTopLevel', 'reason'], 'responsive' : ['processId'], @@ -38,6 +37,7 @@ var createEvent = function(name) { return new eventBindings.Event(name, undefined, eventOpts); }; +var consoleMessageEvent = createEvent('webview.onConsoleMessage'); var contentLoadEvent = createEvent('webview.onContentLoad'); var loadCommitEvent = createEvent('webview.onLoadCommit'); var loadRedirectEvent = createEvent('webview.onLoadRedirect'); @@ -45,6 +45,10 @@ var loadStartEvent = createEvent('webview.onLoadStart'); var loadStopEvent = createEvent('webview.onLoadStop'); var WEB_VIEW_EXT_EVENTS = { + 'consolemessage': { + evt: consoleMessageEvent, + fields: ['level', 'message', 'line', 'sourceId'] + }, 'contentload': { evt: contentLoadEvent, fields: [] diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc index 1ffc7ad..ff5417d 100644 --- a/content/browser/browser_plugin/browser_plugin_guest.cc +++ b/content/browser/browser_plugin/browser_plugin_guest.cc @@ -301,19 +301,11 @@ bool BrowserPluginGuest::AddMessageToConsole(WebContents* source, const string16& message, int32 line_no, const string16& source_id) { - base::DictionaryValue message_info; - // Log levels are from base/logging.h: LogSeverity. - message_info.Set(browser_plugin::kLevel, - base::Value::CreateIntegerValue(level)); - message_info.Set(browser_plugin::kMessage, - base::Value::CreateStringValue(message)); - message_info.Set(browser_plugin::kLine, - base::Value::CreateIntegerValue(line_no)); - message_info.Set(browser_plugin::kSourceId, - base::Value::CreateStringValue(source_id)); - SendMessageToEmbedder( - new BrowserPluginMsg_AddMessageToConsole(instance_id_, message_info)); - return false; + if (!delegate_) + return false; + + delegate_->AddMessageToConsole(level, message, line_no, source_id); + return true; } void BrowserPluginGuest::DestroyUnattachedWindows() { @@ -475,8 +467,10 @@ BrowserPluginGuest* BrowserPluginGuest::Create( guest = new BrowserPluginGuest(instance_id, web_contents, NULL, false); } web_contents->SetBrowserPluginGuest(guest); + BrowserPluginGuestDelegate* delegate = NULL; GetContentClient()->browser()->GuestWebContentsCreated( - web_contents, NULL, extra_params.Pass()); + web_contents, NULL, &delegate, extra_params.Pass()); + guest->SetDelegate(delegate); return guest; } @@ -490,9 +484,11 @@ BrowserPluginGuest* BrowserPluginGuest::CreateWithOpener( new BrowserPluginGuest( instance_id, web_contents, opener, has_render_view); web_contents->SetBrowserPluginGuest(guest); + BrowserPluginGuestDelegate* delegate = NULL; GetContentClient()->browser()->GuestWebContentsCreated( - web_contents, opener->GetWebContents(), + web_contents, opener->GetWebContents(), &delegate, scoped_ptr<base::DictionaryValue>()); + guest->SetDelegate(delegate); return guest; } @@ -805,6 +801,11 @@ void BrowserPluginGuest::EndSystemDrag() { guest_rvh->ForwardMouseEvent(mouse_event); } +void BrowserPluginGuest::SetDelegate(BrowserPluginGuestDelegate* delegate) { + DCHECK(!delegate_); + delegate_.reset(delegate); +} + void BrowserPluginGuest::AskEmbedderForGeolocationPermission( int bridge_id, const GURL& requesting_frame, diff --git a/content/browser/browser_plugin/browser_plugin_guest.h b/content/browser/browser_plugin/browser_plugin_guest.h index f27d418..3e81167 100644 --- a/content/browser/browser_plugin/browser_plugin_guest.h +++ b/content/browser/browser_plugin/browser_plugin_guest.h @@ -32,6 +32,7 @@ #include "content/common/browser_plugin/browser_plugin_message_enums.h" #include "content/common/edit_command.h" #include "content/port/common/input_event_ack_state.h" +#include "content/public/browser/browser_plugin_guest_delegate.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/render_view_host_observer.h" @@ -261,6 +262,9 @@ class CONTENT_EXPORT BrowserPluginGuest // Called when the drag started by this guest ends at an OS-level. void EndSystemDrag(); + // |this| takes ownership of |delegate|. + void SetDelegate(BrowserPluginGuestDelegate* delegate); + private: class EmbedderRenderViewHostObserver; friend class TestBrowserPluginGuest; @@ -490,6 +494,8 @@ class CONTENT_EXPORT BrowserPluginGuest // once the guest is attached to a particular embedder. std::queue<IPC::Message*> pending_messages_; + scoped_ptr<BrowserPluginGuestDelegate> delegate_; + DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); }; diff --git a/content/common/browser_plugin/browser_plugin_constants.cc b/content/common/browser_plugin/browser_plugin_constants.cc index 2a55dc6..f8a8433f 100644 --- a/content/common/browser_plugin/browser_plugin_constants.cc +++ b/content/common/browser_plugin/browser_plugin_constants.cc @@ -42,7 +42,6 @@ const char kAttributeSrc[] = "src"; // Events. const char kEventClose[] = "close"; -const char kEventConsoleMessage[] = "consolemessage"; const char kEventExit[] = "exit"; const char kEventLoadAbort[] = "loadabort"; const char kEventLoadStart[] = "loadstart"; @@ -57,9 +56,6 @@ const char kInitialHeight[] = "initialHeight"; const char kInitialWidth[] = "initialWidth"; const char kIsTopLevel[] = "isTopLevel"; const char kLastUnlockedBySelf[] = "lastUnlockedBySelf"; -const char kLevel[] = "level"; -const char kLine[] = "line"; -const char kMessage[] = "message"; const char kName[] = "name"; const char kNewHeight[] = "newHeight"; const char kNewWidth[] = "newWidth"; @@ -76,7 +72,6 @@ const char kProcessId[] = "processId"; const char kReason[] = "reason"; const char kRequestId[] = "requestId"; const char kRequestMethod[] = "requestMethod"; -const char kSourceId[] = "sourceId"; const char kTargetURL[] = "targetUrl"; const char kURL[] = "url"; const char kWindowID[] = "windowId"; diff --git a/content/common/browser_plugin/browser_plugin_constants.h b/content/common/browser_plugin/browser_plugin_constants.h index 3fff677..6a8b3d7 100644 --- a/content/common/browser_plugin/browser_plugin_constants.h +++ b/content/common/browser_plugin/browser_plugin_constants.h @@ -43,7 +43,6 @@ extern const char kAttributeSrc[]; // Events. extern const char kEventClose[]; -extern const char kEventConsoleMessage[]; extern const char kEventExit[]; extern const char kEventLoadAbort[]; extern const char kEventLoadStart[]; @@ -58,9 +57,6 @@ extern const char kInitialHeight[]; extern const char kInitialWidth[]; extern const char kIsTopLevel[]; extern const char kLastUnlockedBySelf[]; -extern const char kLevel[]; -extern const char kLine[]; -extern const char kMessage[]; extern const char kName[]; extern const char kNewHeight[]; extern const char kNewWidth[]; @@ -77,7 +73,6 @@ extern const char kProcessId[]; extern const char kReason[]; extern const char kRequestId[]; extern const char kRequestMethod[]; -extern const char kSourceId[]; extern const char kTargetURL[]; extern const char kURL[]; extern const char kUserGesture[]; diff --git a/content/common/browser_plugin/browser_plugin_messages.h b/content/common/browser_plugin/browser_plugin_messages.h index 4f3541d..96c8339 100644 --- a/content/common/browser_plugin/browser_plugin_messages.h +++ b/content/common/browser_plugin/browser_plugin_messages.h @@ -310,10 +310,6 @@ IPC_MESSAGE_ROUTED2(BrowserPluginMsg_AllocateInstanceID_ACK, int /* request_id */, int /* instance_id */) -IPC_MESSAGE_CONTROL2(BrowserPluginMsg_AddMessageToConsole, - int /* instance_id */, - base::DictionaryValue /* message_info */) - // This message is sent in response to a completed attachment of a guest // to a BrowserPlugin. This message carries information about the guest // that is used to update the attributes of the browser plugin. diff --git a/content/content_browser.gypi b/content/content_browser.gypi index e5b3252..3cd7e2c 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -51,6 +51,7 @@ 'public/browser/browser_main_runner.h', 'public/browser/browser_message_filter.cc', 'public/browser/browser_message_filter.h', + 'public/browser/browser_plugin_guest_delegate.h', 'public/browser/browser_ppapi_host.h', 'public/browser/browser_shutdown.h', 'public/browser/browser_url_handler.h', diff --git a/content/public/browser/browser_plugin_guest_delegate.h b/content/public/browser/browser_plugin_guest_delegate.h new file mode 100644 index 0000000..fdcb523 --- /dev/null +++ b/content/public/browser/browser_plugin_guest_delegate.h @@ -0,0 +1,27 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_PUBLIC_BROWSER_BROWSER_PLUGIN_GUEST_DELEGATE_H_ +#define CONTENT_PUBLIC_BROWSER_BROWSER_PLUGIN_GUEST_DELEGATE_H_ + +#include "base/strings/string16.h" + +namespace content { + +// Objects implement this interface to get notified about changes in the guest +// WebContents and to provide necessary functionality. +class BrowserPluginGuestDelegate { + public: + virtual ~BrowserPluginGuestDelegate() {} + + // Add a message to the console. + virtual void AddMessageToConsole(int32 level, + const string16& message, + int32 line_no, + const string16& source_id) {} +}; + +} // namespace content + +#endif // CONTENT_PUBLIC_BROWSER_BROWSER_PLUGIN_GUEST_DELEGATE_H_ diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h index 659e0d4..5bbba9a 100644 --- a/content/public/browser/content_browser_client.h +++ b/content/public/browser/content_browser_client.h @@ -81,6 +81,7 @@ class AccessTokenStore; class BrowserChildProcessHost; class BrowserContext; class BrowserMainParts; +class BrowserPluginGuestDelegate; class BrowserPpapiHost; class BrowserURLHandler; class LocationProvider; @@ -143,10 +144,13 @@ class CONTENT_EXPORT ContentBrowserClient { // If the guest was created via navigation, then |extra_params| will be // non-NULL. |extra_params| are parameters passed to the BrowserPlugin object // element by the content embedder. These parameters may include the API to - // enable for the given guest. + // enable for the given guest. |guest_delegate| is a return parameter of + // the delegate in the content embedder that will service the guest in the + // content layer. The content layer takes ownership of the |guest_delegate|. virtual void GuestWebContentsCreated( WebContents* guest_web_contents, WebContents* opener_web_contents, + BrowserPluginGuestDelegate** guest_delegate, scoped_ptr<base::DictionaryValue> extra_params) {} // Notifies that a guest WebContents has been attached to a BrowserPlugin. diff --git a/content/renderer/browser_plugin/browser_plugin.cc b/content/renderer/browser_plugin/browser_plugin.cc index db93912..898cd7d 100644 --- a/content/renderer/browser_plugin/browser_plugin.cc +++ b/content/renderer/browser_plugin/browser_plugin.cc @@ -155,8 +155,6 @@ BrowserPlugin* BrowserPlugin::FromContainer( bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) - IPC_MESSAGE_HANDLER(BrowserPluginMsg_AddMessageToConsole, - OnAddMessageToConsole) IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) IPC_MESSAGE_HANDLER(BrowserPluginMsg_Attach_ACK, OnAttachACK) IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped) @@ -448,17 +446,6 @@ void BrowserPlugin::DidCommitCompositorFrame() { compositing_helper_->DidCommitCompositorFrame(); } -void BrowserPlugin::OnAddMessageToConsole( - int guest_instance_id, const base::DictionaryValue& message_info) { - std::map<std::string, base::Value*> props; - // Fill in the info provided by the browser. - for (base::DictionaryValue::Iterator iter(message_info); !iter.IsAtEnd(); - iter.Advance()) { - props[iter.key()] = iter.value().DeepCopy(); - } - TriggerEvent(browser_plugin::kEventConsoleMessage, &props); -} - void BrowserPlugin::OnAdvanceFocus(int guest_instance_id, bool reverse) { DCHECK(render_view_.get()); render_view_->GetWebView()->advanceFocus(reverse); @@ -1255,7 +1242,6 @@ gfx::Point BrowserPlugin::ToLocalCoordinates(const gfx::Point& point) const { bool BrowserPlugin::ShouldForwardToBrowserPlugin( const IPC::Message& message) { switch (message.type()) { - case BrowserPluginMsg_AddMessageToConsole::ID: case BrowserPluginMsg_AdvanceFocus::ID: case BrowserPluginMsg_Attach_ACK::ID: case BrowserPluginMsg_BuffersSwapped::ID: diff --git a/content/renderer/browser_plugin/browser_plugin.h b/content/renderer/browser_plugin/browser_plugin.h index d7df19b..bfb2bc7 100644 --- a/content/renderer/browser_plugin/browser_plugin.h +++ b/content/renderer/browser_plugin/browser_plugin.h @@ -324,9 +324,6 @@ class CONTENT_EXPORT BrowserPlugin : // IPC message handlers. // Please keep in alphabetical order. - void OnAddMessageToConsole( - int instance_id, - const base::DictionaryValue& message_info); void OnAdvanceFocus(int instance_id, bool reverse); void OnAttachACK(int instance_id, const BrowserPluginMsg_Attach_ACK_Params& ack_params); |