OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "extensions/browser/guest_view/extension_options/extension_options_gues
t.h" | 5 #include "extensions/browser/guest_view/extension_options/extension_options_gues
t.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "components/crx_file/id_util.h" | 8 #include "components/crx_file/id_util.h" |
9 #include "content/public/browser/render_process_host.h" | 9 #include "content/public/browser/render_process_host.h" |
10 #include "content/public/browser/site_instance.h" | 10 #include "content/public/browser/site_instance.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 } | 44 } |
45 | 45 |
46 ExtensionOptionsGuest::~ExtensionOptionsGuest() { | 46 ExtensionOptionsGuest::~ExtensionOptionsGuest() { |
47 } | 47 } |
48 | 48 |
49 // static | 49 // static |
50 extensions::GuestViewBase* ExtensionOptionsGuest::Create( | 50 extensions::GuestViewBase* ExtensionOptionsGuest::Create( |
51 content::BrowserContext* browser_context, | 51 content::BrowserContext* browser_context, |
52 int guest_instance_id) { | 52 int guest_instance_id) { |
53 if (!extensions::FeatureSwitch::embedded_extension_options()->IsEnabled()) { | 53 if (!extensions::FeatureSwitch::embedded_extension_options()->IsEnabled()) { |
54 return NULL; | 54 return nullptr; |
55 } | 55 } |
56 return new ExtensionOptionsGuest(browser_context, guest_instance_id); | 56 return new ExtensionOptionsGuest(browser_context, guest_instance_id); |
57 } | 57 } |
58 | 58 |
59 void ExtensionOptionsGuest::CreateWebContents( | 59 void ExtensionOptionsGuest::CreateWebContents( |
60 const std::string& embedder_extension_id, | 60 const std::string& embedder_extension_id, |
61 int embedder_render_process_id, | 61 int embedder_render_process_id, |
62 const base::DictionaryValue& create_params, | 62 const base::DictionaryValue& create_params, |
63 const WebContentsCreatedCallback& callback) { | 63 const WebContentsCreatedCallback& callback) { |
64 // Get the extension's base URL. | 64 // Get the extension's base URL. |
65 std::string extension_id; | 65 std::string extension_id; |
66 create_params.GetString(extensionoptions::kExtensionId, &extension_id); | 66 create_params.GetString(extensionoptions::kExtensionId, &extension_id); |
67 | 67 |
68 if (!crx_file::id_util::IdIsValid(extension_id)) { | 68 if (!crx_file::id_util::IdIsValid(extension_id)) { |
69 callback.Run(NULL); | 69 callback.Run(nullptr); |
70 return; | 70 return; |
71 } | 71 } |
72 | 72 |
73 if (crx_file::id_util::IdIsValid(embedder_extension_id) && | 73 if (crx_file::id_util::IdIsValid(embedder_extension_id) && |
74 extension_id != embedder_extension_id) { | 74 extension_id != embedder_extension_id) { |
75 // Extensions cannot embed other extensions' options pages. | 75 // Extensions cannot embed other extensions' options pages. |
76 callback.Run(NULL); | 76 callback.Run(nullptr); |
77 return; | 77 return; |
78 } | 78 } |
79 | 79 |
80 GURL extension_url = | 80 GURL extension_url = |
81 extensions::Extension::GetBaseURLFromExtensionId(extension_id); | 81 extensions::Extension::GetBaseURLFromExtensionId(extension_id); |
82 if (!extension_url.is_valid()) { | 82 if (!extension_url.is_valid()) { |
83 callback.Run(NULL); | 83 callback.Run(nullptr); |
84 return; | 84 return; |
85 } | 85 } |
86 | 86 |
87 // Get the options page URL for later use. | 87 // Get the options page URL for later use. |
88 extensions::ExtensionRegistry* registry = | 88 extensions::ExtensionRegistry* registry = |
89 extensions::ExtensionRegistry::Get(browser_context()); | 89 extensions::ExtensionRegistry::Get(browser_context()); |
90 const extensions::Extension* extension = | 90 const extensions::Extension* extension = |
91 registry->enabled_extensions().GetByID(extension_id); | 91 registry->enabled_extensions().GetByID(extension_id); |
92 options_page_ = extensions::OptionsPageInfo::GetOptionsPage(extension); | 92 options_page_ = extensions::OptionsPageInfo::GetOptionsPage(extension); |
93 if (!options_page_.is_valid()) { | 93 if (!options_page_.is_valid()) { |
94 callback.Run(NULL); | 94 callback.Run(nullptr); |
95 return; | 95 return; |
96 } | 96 } |
97 | 97 |
98 // Create a WebContents using the extension URL. The options page's | 98 // Create a WebContents using the extension URL. The options page's |
99 // WebContents should live in the same process as its parent extension's | 99 // WebContents should live in the same process as its parent extension's |
100 // WebContents, so we can use |extension_url| for creating the SiteInstance. | 100 // WebContents, so we can use |extension_url| for creating the SiteInstance. |
101 content::SiteInstance* options_site_instance = | 101 content::SiteInstance* options_site_instance = |
102 content::SiteInstance::CreateForURL(browser_context(), extension_url); | 102 content::SiteInstance::CreateForURL(browser_context(), extension_url); |
103 WebContents::CreateParams params(browser_context(), options_site_instance); | 103 WebContents::CreateParams params(browser_context(), options_site_instance); |
104 params.guest_delegate = this; | 104 params.guest_delegate = this; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 } | 152 } |
153 | 153 |
154 content::WebContents* ExtensionOptionsGuest::GetAssociatedWebContents() const { | 154 content::WebContents* ExtensionOptionsGuest::GetAssociatedWebContents() const { |
155 return web_contents(); | 155 return web_contents(); |
156 } | 156 } |
157 | 157 |
158 content::WebContents* ExtensionOptionsGuest::OpenURLFromTab( | 158 content::WebContents* ExtensionOptionsGuest::OpenURLFromTab( |
159 content::WebContents* source, | 159 content::WebContents* source, |
160 const content::OpenURLParams& params) { | 160 const content::OpenURLParams& params) { |
161 if (!extension_options_guest_delegate_) | 161 if (!extension_options_guest_delegate_) |
162 return NULL; | 162 return nullptr; |
163 | 163 |
164 // Don't allow external URLs with the CURRENT_TAB disposition be opened in | 164 // Don't allow external URLs with the CURRENT_TAB disposition be opened in |
165 // this guest view, change the disposition to NEW_FOREGROUND_TAB. | 165 // this guest view, change the disposition to NEW_FOREGROUND_TAB. |
166 if ((!params.url.SchemeIs(extensions::kExtensionScheme) || | 166 if ((!params.url.SchemeIs(extensions::kExtensionScheme) || |
167 params.url.host() != options_page_.host()) && | 167 params.url.host() != options_page_.host()) && |
168 params.disposition == CURRENT_TAB) { | 168 params.disposition == CURRENT_TAB) { |
169 return extension_options_guest_delegate_->OpenURLInNewTab( | 169 return extension_options_guest_delegate_->OpenURLInNewTab( |
170 content::OpenURLParams(params.url, | 170 content::OpenURLParams(params.url, |
171 params.referrer, | 171 params.referrer, |
172 params.frame_tree_node_id, | 172 params.frame_tree_node_id, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 attach_params()->GetInteger(extensionoptions::kAttributeMinWidth, &min_width); | 251 attach_params()->GetInteger(extensionoptions::kAttributeMinWidth, &min_width); |
252 | 252 |
253 // Call SetAutoSize to apply all the appropriate validation and clipping of | 253 // Call SetAutoSize to apply all the appropriate validation and clipping of |
254 // values. | 254 // values. |
255 SetAutoSize(auto_size_enabled, | 255 SetAutoSize(auto_size_enabled, |
256 gfx::Size(min_width, min_height), | 256 gfx::Size(min_width, min_height), |
257 gfx::Size(max_width, max_height)); | 257 gfx::Size(max_width, max_height)); |
258 } | 258 } |
259 | 259 |
260 } // namespace extensions | 260 } // namespace extensions |
OLD | NEW |