| 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/metrics/user_metrics.h" | 7 #include "base/metrics/user_metrics.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "components/crx_file/id_util.h" | 9 #include "components/crx_file/id_util.h" |
| 10 #include "content/public/browser/navigation_details.h" | 10 #include "content/public/browser/navigation_details.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 ExtensionOptionsGuest::ExtensionOptionsGuest( | 39 ExtensionOptionsGuest::ExtensionOptionsGuest( |
| 40 content::BrowserContext* browser_context, | 40 content::BrowserContext* browser_context, |
| 41 content::WebContents* owner_web_contents, | 41 content::WebContents* owner_web_contents, |
| 42 int guest_instance_id) | 42 int guest_instance_id) |
| 43 : GuestView<ExtensionOptionsGuest>(browser_context, | 43 : GuestView<ExtensionOptionsGuest>(browser_context, |
| 44 owner_web_contents, | 44 owner_web_contents, |
| 45 guest_instance_id), | 45 guest_instance_id), |
| 46 extension_options_guest_delegate_( | 46 extension_options_guest_delegate_( |
| 47 extensions::ExtensionsAPIClient::Get() | 47 extensions::ExtensionsAPIClient::Get() |
| 48 ->CreateExtensionOptionsGuestDelegate(this)), | 48 ->CreateExtensionOptionsGuestDelegate(this)) { |
| 49 has_navigated_(false) { | |
| 50 } | 49 } |
| 51 | 50 |
| 52 ExtensionOptionsGuest::~ExtensionOptionsGuest() { | 51 ExtensionOptionsGuest::~ExtensionOptionsGuest() { |
| 53 } | 52 } |
| 54 | 53 |
| 55 // static | 54 // static |
| 56 extensions::GuestViewBase* ExtensionOptionsGuest::Create( | 55 extensions::GuestViewBase* ExtensionOptionsGuest::Create( |
| 57 content::BrowserContext* browser_context, | 56 content::BrowserContext* browser_context, |
| 58 content::WebContents* owner_web_contents, | 57 content::WebContents* owner_web_contents, |
| 59 int guest_instance_id) { | 58 int guest_instance_id) { |
| 60 return new ExtensionOptionsGuest(browser_context, | 59 return new ExtensionOptionsGuest(browser_context, |
| 61 owner_web_contents, | 60 owner_web_contents, |
| 62 guest_instance_id); | 61 guest_instance_id); |
| 63 } | 62 } |
| 64 | 63 |
| 64 bool ExtensionOptionsGuest::CanRunInDetachedState() const { |
| 65 return true; |
| 66 } |
| 67 |
| 65 void ExtensionOptionsGuest::CreateWebContents( | 68 void ExtensionOptionsGuest::CreateWebContents( |
| 66 const base::DictionaryValue& create_params, | 69 const base::DictionaryValue& create_params, |
| 67 const WebContentsCreatedCallback& callback) { | 70 const WebContentsCreatedCallback& callback) { |
| 68 // Get the extension's base URL. | 71 // Get the extension's base URL. |
| 69 std::string extension_id; | 72 std::string extension_id; |
| 70 create_params.GetString(extensionoptions::kExtensionId, &extension_id); | 73 create_params.GetString(extensionoptions::kExtensionId, &extension_id); |
| 71 | 74 |
| 72 if (!crx_file::id_util::IdIsValid(extension_id)) { | 75 if (!crx_file::id_util::IdIsValid(extension_id)) { |
| 73 callback.Run(NULL); | 76 callback.Run(NULL); |
| 74 return; | 77 return; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // Create a WebContents using the extension URL. The options page's | 113 // Create a WebContents using the extension URL. The options page's |
| 111 // WebContents should live in the same process as its parent extension's | 114 // WebContents should live in the same process as its parent extension's |
| 112 // WebContents, so we can use |extension_url| for creating the SiteInstance. | 115 // WebContents, so we can use |extension_url| for creating the SiteInstance. |
| 113 content::SiteInstance* options_site_instance = | 116 content::SiteInstance* options_site_instance = |
| 114 content::SiteInstance::CreateForURL(browser_context(), extension_url); | 117 content::SiteInstance::CreateForURL(browser_context(), extension_url); |
| 115 WebContents::CreateParams params(browser_context(), options_site_instance); | 118 WebContents::CreateParams params(browser_context(), options_site_instance); |
| 116 params.guest_delegate = this; | 119 params.guest_delegate = this; |
| 117 callback.Run(WebContents::Create(params)); | 120 callback.Run(WebContents::Create(params)); |
| 118 } | 121 } |
| 119 | 122 |
| 120 void ExtensionOptionsGuest::DidAttachToEmbedder() { | |
| 121 // We should not re-navigate on reattachment. | |
| 122 if (has_navigated_) | |
| 123 return; | |
| 124 | |
| 125 web_contents()->GetController().LoadURL(options_page_, | |
| 126 content::Referrer(), | |
| 127 ui::PAGE_TRANSITION_LINK, | |
| 128 std::string()); | |
| 129 has_navigated_ = true; | |
| 130 } | |
| 131 | |
| 132 void ExtensionOptionsGuest::DidInitialize( | 123 void ExtensionOptionsGuest::DidInitialize( |
| 133 const base::DictionaryValue& create_params) { | 124 const base::DictionaryValue& create_params) { |
| 134 extension_function_dispatcher_.reset( | 125 extension_function_dispatcher_.reset( |
| 135 new extensions::ExtensionFunctionDispatcher(browser_context(), this)); | 126 new extensions::ExtensionFunctionDispatcher(browser_context(), this)); |
| 136 if (extension_options_guest_delegate_) { | 127 if (extension_options_guest_delegate_) { |
| 137 extension_options_guest_delegate_->DidInitialize(); | 128 extension_options_guest_delegate_->DidInitialize(); |
| 138 } | 129 } |
| 130 web_contents()->GetController().LoadURL(options_page_, |
| 131 content::Referrer(), |
| 132 ui::PAGE_TRANSITION_LINK, |
| 133 std::string()); |
| 139 } | 134 } |
| 140 | 135 |
| 141 void ExtensionOptionsGuest::DidStopLoading() { | 136 void ExtensionOptionsGuest::DidStopLoading() { |
| 142 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 137 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 143 DispatchEventToEmbedder(new extensions::GuestViewBase::Event( | 138 DispatchEventToEmbedder(new extensions::GuestViewBase::Event( |
| 144 extension_options_internal::OnLoad::kEventName, args.Pass())); | 139 extension_options_internal::OnLoad::kEventName, args.Pass())); |
| 145 } | 140 } |
| 146 | 141 |
| 147 const char* ExtensionOptionsGuest::GetAPINamespace() const { | 142 const char* ExtensionOptionsGuest::GetAPINamespace() const { |
| 148 return extensionoptions::kAPINamespace; | 143 return extensionoptions::kAPINamespace; |
| 149 } | 144 } |
| 150 | 145 |
| 151 int ExtensionOptionsGuest::GetTaskPrefix() const { | 146 int ExtensionOptionsGuest::GetTaskPrefix() const { |
| 152 return IDS_EXTENSION_TASK_MANAGER_EXTENSIONOPTIONS_TAG_PREFIX; | 147 return IDS_EXTENSION_TASK_MANAGER_EXTENSIONOPTIONS_TAG_PREFIX; |
| 153 } | 148 } |
| 154 | 149 |
| 155 void ExtensionOptionsGuest::GuestSizeChangedDueToAutoSize( | 150 void ExtensionOptionsGuest::GuestSizeChangedDueToAutoSize( |
| 156 const gfx::Size& old_size, | 151 const gfx::Size& old_size, |
| 157 const gfx::Size& new_size) { | 152 const gfx::Size& new_size) { |
| 158 extension_options_internal::SizeChangedOptions options; | 153 extension_options_internal::SizeChangedOptions options; |
| 159 options.old_width = old_size.width(); | 154 options.old_width = old_size.width(); |
| 160 options.old_height = old_size.height(); | 155 options.old_height = old_size.height(); |
| 161 options.new_width = new_size.width(); | 156 options.new_width = new_size.width(); |
| 162 options.new_height = new_size.height(); | 157 options.new_height = new_size.height(); |
| 163 DispatchEventToEmbedder(new extensions::GuestViewBase::Event( | 158 DispatchEventToEmbedder(new extensions::GuestViewBase::Event( |
| 164 extension_options_internal::OnSizeChanged::kEventName, | 159 extension_options_internal::OnSizeChanged::kEventName, |
| 165 options.ToValue())); | 160 options.ToValue())); |
| 166 } | 161 } |
| 167 | 162 |
| 163 bool ExtensionOptionsGuest::IsAutoSizeSupported() const { |
| 164 return true; |
| 165 } |
| 166 |
| 167 bool ExtensionOptionsGuest::IsPreferredSizeModeEnabled() const { |
| 168 return true; |
| 169 } |
| 170 |
| 168 void ExtensionOptionsGuest::OnPreferredSizeChanged(const gfx::Size& pref_size) { | 171 void ExtensionOptionsGuest::OnPreferredSizeChanged(const gfx::Size& pref_size) { |
| 169 extension_options_internal::PreferredSizeChangedOptions options; | 172 extension_options_internal::PreferredSizeChangedOptions options; |
| 170 options.width = pref_size.width(); | 173 options.width = pref_size.width(); |
| 171 options.height = pref_size.height(); | 174 options.height = pref_size.height(); |
| 172 DispatchEventToEmbedder(new extensions::GuestViewBase::Event( | 175 DispatchEventToEmbedder(new extensions::GuestViewBase::Event( |
| 173 extension_options_internal::OnPreferredSizeChanged::kEventName, | 176 extension_options_internal::OnPreferredSizeChanged::kEventName, |
| 174 options.ToValue())); | 177 options.ToValue())); |
| 175 } | 178 } |
| 176 | 179 |
| 177 bool ExtensionOptionsGuest::IsAutoSizeSupported() const { | |
| 178 return true; | |
| 179 } | |
| 180 | |
| 181 bool ExtensionOptionsGuest::IsPreferredSizeModeEnabled() const { | |
| 182 return true; | |
| 183 } | |
| 184 | |
| 185 content::WebContents* ExtensionOptionsGuest::GetAssociatedWebContents() const { | 180 content::WebContents* ExtensionOptionsGuest::GetAssociatedWebContents() const { |
| 186 return web_contents(); | 181 return web_contents(); |
| 187 } | 182 } |
| 188 | 183 |
| 189 content::WebContents* ExtensionOptionsGuest::OpenURLFromTab( | 184 content::WebContents* ExtensionOptionsGuest::OpenURLFromTab( |
| 190 content::WebContents* source, | 185 content::WebContents* source, |
| 191 const content::OpenURLParams& params) { | 186 const content::OpenURLParams& params) { |
| 192 if (!extension_options_guest_delegate_) | 187 if (!extension_options_guest_delegate_) |
| 193 return NULL; | 188 return NULL; |
| 194 | 189 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 return handled; | 263 return handled; |
| 269 } | 264 } |
| 270 | 265 |
| 271 void ExtensionOptionsGuest::OnRequest( | 266 void ExtensionOptionsGuest::OnRequest( |
| 272 const ExtensionHostMsg_Request_Params& params) { | 267 const ExtensionHostMsg_Request_Params& params) { |
| 273 extension_function_dispatcher_->Dispatch(params, | 268 extension_function_dispatcher_->Dispatch(params, |
| 274 web_contents()->GetRenderViewHost()); | 269 web_contents()->GetRenderViewHost()); |
| 275 } | 270 } |
| 276 | 271 |
| 277 } // namespace extensions | 272 } // namespace extensions |
| OLD | NEW |