Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/guest_view/extension_options/extension_options_guest.h" | |
| 6 | |
| 7 #include "chrome/browser/guest_view/extension_options/extension_options_constant s.h" | |
| 8 #include "chrome/common/extensions/manifest_url_handler.h" | |
| 9 #include "content/public/browser/render_process_host.h" | |
| 10 #include "content/public/browser/site_instance.h" | |
| 11 #include "content/public/browser/web_contents.h" | |
| 12 #include "extensions/browser/extension_function_dispatcher.h" | |
| 13 #include "extensions/browser/extension_registry.h" | |
| 14 #include "extensions/common/extension.h" | |
| 15 #include "extensions/common/extension_messages.h" | |
| 16 #include "ipc/ipc_message_macros.h" | |
| 17 | |
| 18 using content::WebContents; | |
| 19 | |
| 20 // static | |
| 21 const char ExtensionOptionsGuest::Type[] = "extensionoptions"; | |
| 22 | |
| 23 ExtensionOptionsGuest::ExtensionOptionsGuest( | |
| 24 content::BrowserContext* browser_context, | |
| 25 int guest_instance_id) | |
| 26 : GuestView<ExtensionOptionsGuest>(browser_context, guest_instance_id) {} | |
| 27 | |
| 28 ExtensionOptionsGuest::~ExtensionOptionsGuest() {} | |
| 29 | |
| 30 void ExtensionOptionsGuest::DidAttachToEmbedder() { | |
| 31 guest_web_contents()->GetController().LoadURL(options_page_, | |
| 32 content::Referrer(), | |
| 33 content::PAGE_TRANSITION_LINK, | |
| 34 std::string()); | |
| 35 } | |
| 36 | |
| 37 void ExtensionOptionsGuest::DidInitialize() { | |
| 38 extension_function_dispatcher_.reset( | |
| 39 new extensions::ExtensionFunctionDispatcher(browser_context(), this)); | |
| 40 } | |
| 41 | |
| 42 void ExtensionOptionsGuest::CreateWebContents( | |
| 43 const std::string& embedder_extension_id, | |
| 44 int embedder_render_process_id, | |
| 45 const base::DictionaryValue& create_params, | |
| 46 const WebContentsCreatedCallback& callback) { | |
| 47 content::RenderProcessHost* embedder_render_process_host = | |
| 48 content::RenderProcessHost::FromID(embedder_render_process_id); | |
| 49 content::BrowserContext* browser_context = | |
| 50 embedder_render_process_host->GetBrowserContext(); | |
| 51 | |
| 52 // Get the extension's base URL | |
| 53 std::string extension_id; | |
| 54 create_params.GetString(extensionoptions::kExtensionId, &extension_id); | |
| 55 DCHECK(!extension_id.empty()); | |
|
Fady Samuel
2014/07/11 21:08:05
if (extension_id.empty())) {
callback.Run(NULL);
ericzeng
2014/07/12 00:10:04
Done.
| |
| 56 GURL extensionUrl = | |
|
Fady Samuel
2014/07/11 21:08:05
extension_url
ericzeng
2014/07/12 00:10:04
Done.
| |
| 57 extensions::Extension::GetBaseURLFromExtensionId(extension_id); | |
|
Fady Samuel
2014/07/11 21:08:05
Check that this URL is valid. I would be surprised
ericzeng
2014/07/12 00:10:04
Done.
| |
| 58 | |
| 59 // Get the options page URL for later use | |
| 60 extensions::ExtensionRegistry* registry = | |
| 61 extensions::ExtensionRegistry::Get(browser_context); | |
| 62 const extensions::Extension* extension = | |
| 63 registry->GetExtensionById(extension_id, | |
| 64 extensions::ExtensionRegistry::ENABLED); | |
| 65 options_page_ = extensions::ManifestURL::GetOptionsPage(extension); | |
|
Fady Samuel
2014/07/11 21:08:05
We should probably fail if this extension doesn't
ericzeng
2014/07/12 00:10:04
Done.
| |
| 66 | |
| 67 // Create a Webcontents using the extension URL | |
|
Fady Samuel
2014/07/11 21:08:05
The options page should live in the same process a
| |
| 68 content::SiteInstance* options_site_instance = | |
| 69 content::SiteInstance::CreateForURL(browser_context, extensionUrl); | |
| 70 WebContents::CreateParams params(browser_context, | |
| 71 options_site_instance); | |
| 72 params.guest_delegate = this; | |
| 73 callback.Run(WebContents::Create(params)); | |
| 74 } | |
| 75 | |
| 76 content::WebContents* ExtensionOptionsGuest::GetAssociatedWebContents() const { | |
| 77 return guest_web_contents(); | |
| 78 } | |
| 79 | |
| 80 bool ExtensionOptionsGuest::OnMessageReceived(const IPC::Message& message) { | |
| 81 bool handled = true; | |
| 82 IPC_BEGIN_MESSAGE_MAP(ExtensionOptionsGuest, message) | |
| 83 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | |
| 84 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 85 IPC_END_MESSAGE_MAP() | |
| 86 return handled; | |
| 87 } | |
| 88 | |
| 89 void ExtensionOptionsGuest::OnRequest( | |
| 90 const ExtensionHostMsg_Request_Params¶ms) { | |
| 91 extension_function_dispatcher_->Dispatch( | |
| 92 params, guest_web_contents()->GetRenderViewHost()); | |
| 93 } | |
| OLD | NEW |