Index: extensions/browser/guest_view/extension_view/extension_view_guest.cc |
diff --git a/extensions/browser/guest_view/extension_view/extension_view_guest.cc b/extensions/browser/guest_view/extension_view/extension_view_guest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..12b3030fdcf0266de7af77d6ac83f865e0e2b5ea |
--- /dev/null |
+++ b/extensions/browser/guest_view/extension_view/extension_view_guest.cc |
@@ -0,0 +1,160 @@ |
+// Copyright 2015 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. |
+ |
+#include "extensions/browser/guest_view/extension_view/extension_view_guest.h" |
+ |
+#include "base/metrics/user_metrics.h" |
+#include "content/public/browser/render_process_host.h" |
+#include "content/public/common/result_codes.h" |
+#include "extensions/browser/api/extensions_api_client.h" |
+#include "extensions/browser/guest_view/extension_view/extension_view_constants.h" |
+#include "extensions/common/constants.h" |
+#include "extensions/common/extension_messages.h" |
+#include "extensions/strings/grit/extensions_strings.h" |
+ |
+using content::WebContents; |
+using namespace extensions::core_api; |
+ |
+namespace extensions { |
+ |
+// static |
+const char ExtensionViewGuest::Type[] = "extensionview"; |
+ |
+ExtensionViewGuest::ExtensionViewGuest(content::WebContents* owner_web_contents, |
+ int guest_instance_id) |
+ : GuestView<ExtensionViewGuest>(owner_web_contents, guest_instance_id), |
+ extension_view_guest_delegate_( |
+ extensions::ExtensionsAPIClient::Get() |
+ ->CreateExtensionViewGuestDelegate(this)) { |
+} |
+ |
+ExtensionViewGuest::~ExtensionViewGuest() { |
+} |
+ |
+// static |
+extensions::GuestViewBase* ExtensionViewGuest::Create( |
+ content::WebContents* owner_web_contents, |
+ int guest_instance_id) { |
+ return new ExtensionViewGuest(owner_web_contents, guest_instance_id); |
+} |
+ |
+void ExtensionViewGuest::NavigateGuest(const std::string& src, |
+ bool force_navigation) { |
+ if (src.empty()) |
+ return; |
+ |
+ GURL url(src); |
+ if (!force_navigation && (url == view_page_)) |
+ return; |
+ |
+ web_contents()->GetRenderProcessHost()->FilterURL(false, &url); |
+ web_contents()->GetController().LoadURL(url, content::Referrer(), |
+ ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
+ std::string()); |
+ |
+ view_page_ = url; |
+} |
+ |
+// GuestViewBase implementation. |
+void ExtensionViewGuest::CreateWebContents( |
+ const base::DictionaryValue& create_params, |
+ const WebContentsCreatedCallback& callback) { |
+ content::SiteInstance* view_site_instance = |
+ content::SiteInstance::CreateForURL(browser_context(), GetOwnerSiteURL()); |
Fady Samuel
2015/01/26 12:52:02
This doesn't seem right. I think you want to use t
apacible
2015/01/26 22:12:33
Done.
|
+ |
+ WebContents::CreateParams params(browser_context(), view_site_instance); |
+ params.guest_delegate = this; |
+ callback.Run(WebContents::Create(params)); |
+} |
+ |
+void ExtensionViewGuest::DidAttachToEmbedder() { |
+ ApplySrc(*attach_params()); |
+} |
+ |
+void ExtensionViewGuest::DidInitialize( |
+ const base::DictionaryValue& create_params) { |
+ if (extension_view_guest_delegate_) |
+ extension_view_guest_delegate_->DidInitialize(); |
+} |
+ |
+const char* ExtensionViewGuest::GetAPINamespace() const { |
+ return extensionview::kAPINamespace; |
+} |
+ |
+int ExtensionViewGuest::GetTaskPrefix() const { |
+ return IDS_EXTENSION_TASK_MANAGER_EXTENSIONVIEW_TAG_PREFIX; |
+} |
+ |
+// ExtensionFunctionDispatcher::Delegate implementation. |
+content::WebContents* ExtensionViewGuest::GetAssociatedWebContents() const { |
+ return web_contents(); |
+} |
+ |
+// content::WebContentsDelegate implementation. |
+content::WebContents* ExtensionViewGuest::OpenURLFromTab( |
+ content::WebContents* source, |
+ const content::OpenURLParams& params) { |
+ if (!extension_view_guest_delegate_) |
+ return NULL; |
Fady Samuel
2015/01/26 12:52:02
nit: use nullptr
apacible
2015/01/26 22:12:33
I cleaned up this class and end up removing the We
|
+ return extension_view_guest_delegate_->OpenURLInNewTab(params); |
+} |
+ |
+bool ExtensionViewGuest::HandleContextMenu( |
+ const content::ContextMenuParams& params) { |
+ if (!extension_view_guest_delegate_) |
+ return false; |
+ |
+ return extension_view_guest_delegate_->HandleContextMenu(params); |
+} |
+ |
+bool ExtensionViewGuest::ShouldCreateWebContents( |
+ content::WebContents* web_contents, |
+ int route_id, |
+ int main_frame_route_id, |
+ WindowContainerType window_container_type, |
+ const base::string16& frame_name, |
+ const GURL& target_url, |
+ const std::string& partition_id, |
+ content::SessionStorageNamespace* session_storage_namespace) { |
+ if (extension_view_guest_delegate_) { |
+ extension_view_guest_delegate_->OpenURLInNewTab(content::OpenURLParams( |
+ target_url, content::Referrer(), NEW_FOREGROUND_TAB, |
+ ui::PAGE_TRANSITION_LINK, false)); |
+ } |
+ return false; |
+} |
+ |
+// content::WebContentsObserver implementation. |
+void ExtensionViewGuest::DidNavigateMainFrame( |
+ const content::LoadCommittedDetails& details, |
+ const content::FrameNavigateParams& params) { |
+ if (attached() && (params.url.GetOrigin() != view_page_.GetOrigin())) { |
Fady Samuel
2015/01/26 12:52:02
Wow, what's going on here? You're killing the gues
apacible
2015/01/26 22:12:33
I wanted the guest to stay on the same origin, but
|
+ web_contents()->GetRenderProcessHost()->Shutdown( |
+ content::RESULT_CODE_KILLED_BAD_MESSAGE, false /* wait */); |
+ } |
+} |
+ |
+bool ExtensionViewGuest::OnMessageReceived(const IPC::Message& message) { |
+ bool handled = true; |
+ IPC_BEGIN_MESSAGE_MAP(ExtensionViewGuest, message) |
+ IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
+ IPC_MESSAGE_UNHANDLED(handled = false) |
+ IPC_END_MESSAGE_MAP() |
+ return handled; |
+} |
+ |
+// Private |
+void ExtensionViewGuest::OnRequest( |
+ const ExtensionHostMsg_Request_Params& params) { |
+ extension_function_dispatcher_->Dispatch(params, |
+ web_contents()->GetRenderViewHost()); |
+} |
+ |
+void ExtensionViewGuest::ApplySrc(const base::DictionaryValue& params) { |
+ std::string src; |
+ params.GetString(extensionview::kAttributeSrc, &src); |
+ NavigateGuest(src, false /* force_navigation */); |
+} |
+ |
+} // namespace extensions |