Chromium Code Reviews| 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 "chrome/browser/guest_view/extension_options/extension_options_guest.h" | 5 #include "chrome/browser/guest_view/extension_options/extension_options_guest.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 8 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
| 9 #include "chrome/browser/guest_view/extension_options/extension_options_constant s.h" | 9 #include "chrome/browser/guest_view/extension_options/extension_options_constant s.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/common/extensions/api/extension_options_internal.h" | 11 #include "chrome/common/extensions/api/extension_options_internal.h" |
| 12 #include "chrome/common/extensions/manifest_url_handler.h" | 12 #include "chrome/common/extensions/manifest_url_handler.h" |
| 13 #include "content/public/browser/render_process_host.h" | 13 #include "content/public/browser/render_process_host.h" |
| 14 #include "content/public/browser/site_instance.h" | 14 #include "content/public/browser/site_instance.h" |
| 15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "extensions/browser/extension_function_dispatcher.h" | 16 #include "extensions/browser/extension_function_dispatcher.h" |
| 17 #include "extensions/browser/extension_registry.h" | 17 #include "extensions/browser/extension_registry.h" |
| 18 #include "extensions/common/extension.h" | 18 #include "extensions/common/extension.h" |
| 19 #include "extensions/common/extension_messages.h" | 19 #include "extensions/common/extension_messages.h" |
| 20 #include "extensions/common/feature_switch.h" | 20 #include "extensions/common/feature_switch.h" |
| 21 #include "extensions/common/permissions/permissions_data.h" | 21 #include "extensions/common/permissions/permissions_data.h" |
| 22 #include "ipc/ipc_message_macros.h" | 22 #include "ipc/ipc_message_macros.h" |
| 23 | 23 |
| 24 using content::WebContents; | 24 using content::WebContents; |
| 25 using namespace extensions::api; | |
| 25 | 26 |
| 26 // static | 27 // static |
| 27 const char ExtensionOptionsGuest::Type[] = "extensionoptions"; | 28 const char ExtensionOptionsGuest::Type[] = "extensionoptions"; |
| 28 | 29 |
| 29 ExtensionOptionsGuest::ExtensionOptionsGuest( | 30 ExtensionOptionsGuest::ExtensionOptionsGuest( |
| 30 content::BrowserContext* browser_context, | 31 content::BrowserContext* browser_context, |
| 31 int guest_instance_id) | 32 int guest_instance_id) |
| 32 : GuestView<ExtensionOptionsGuest>(browser_context, guest_instance_id) { | 33 : GuestView<ExtensionOptionsGuest>(browser_context, guest_instance_id) { |
| 33 } | 34 } |
| 34 | 35 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 // WebContents should live in the same process as its parent extension's | 94 // WebContents should live in the same process as its parent extension's |
| 94 // WebContents, so we can use |extension_url| for creating the SiteInstance. | 95 // WebContents, so we can use |extension_url| for creating the SiteInstance. |
| 95 content::SiteInstance* options_site_instance = | 96 content::SiteInstance* options_site_instance = |
| 96 content::SiteInstance::CreateForURL(browser_context(), extension_url); | 97 content::SiteInstance::CreateForURL(browser_context(), extension_url); |
| 97 WebContents::CreateParams params(browser_context(), options_site_instance); | 98 WebContents::CreateParams params(browser_context(), options_site_instance); |
| 98 params.guest_delegate = this; | 99 params.guest_delegate = this; |
| 99 callback.Run(WebContents::Create(params)); | 100 callback.Run(WebContents::Create(params)); |
| 100 } | 101 } |
| 101 | 102 |
| 102 void ExtensionOptionsGuest::DidAttachToEmbedder() { | 103 void ExtensionOptionsGuest::DidAttachToEmbedder() { |
| 104 SetUpAutoSize(); | |
| 103 guest_web_contents()->GetController().LoadURL(options_page_, | 105 guest_web_contents()->GetController().LoadURL(options_page_, |
| 104 content::Referrer(), | 106 content::Referrer(), |
| 105 content::PAGE_TRANSITION_LINK, | 107 content::PAGE_TRANSITION_LINK, |
| 106 std::string()); | 108 std::string()); |
| 107 } | 109 } |
| 108 | 110 |
| 109 void ExtensionOptionsGuest::DidInitialize() { | 111 void ExtensionOptionsGuest::DidInitialize() { |
| 110 extension_function_dispatcher_.reset( | 112 extension_function_dispatcher_.reset( |
| 111 new extensions::ExtensionFunctionDispatcher(browser_context(), this)); | 113 new extensions::ExtensionFunctionDispatcher(browser_context(), this)); |
| 112 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | 114 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 131 IPC_MESSAGE_UNHANDLED(handled = false) | 133 IPC_MESSAGE_UNHANDLED(handled = false) |
| 132 IPC_END_MESSAGE_MAP() | 134 IPC_END_MESSAGE_MAP() |
| 133 return handled; | 135 return handled; |
| 134 } | 136 } |
| 135 | 137 |
| 136 void ExtensionOptionsGuest::OnRequest( | 138 void ExtensionOptionsGuest::OnRequest( |
| 137 const ExtensionHostMsg_Request_Params& params) { | 139 const ExtensionHostMsg_Request_Params& params) { |
| 138 extension_function_dispatcher_->Dispatch( | 140 extension_function_dispatcher_->Dispatch( |
| 139 params, guest_web_contents()->GetRenderViewHost()); | 141 params, guest_web_contents()->GetRenderViewHost()); |
| 140 } | 142 } |
| 143 | |
| 144 void ExtensionOptionsGuest::GuestSizeChangedDueToAutoSize( | |
| 145 const gfx::Size& old_size, | |
| 146 const gfx::Size& new_size) { | |
| 147 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | |
| 148 args->SetInteger(extensionoptions::kWidth, new_size.width()); | |
| 149 args->SetInteger(extensionoptions::kHeight, new_size.height()); | |
| 150 DispatchEventToEmbedder(new GuestViewBase::Event( | |
| 151 extension_options_internal::OnSizeChanged::kEventName, args.Pass())); | |
| 152 } | |
| 153 | |
| 154 bool ExtensionOptionsGuest::IsAutoSizeSupported() const { | |
| 155 return true; | |
| 156 } | |
| 157 | |
| 158 void ExtensionOptionsGuest::SetUpAutoSize() { | |
| 159 // Read the autosize parameters passed in from the embedder. | |
| 160 bool auto_size_enabled; | |
|
Fady Samuel
2014/08/08 19:18:15
Initialize this.
| |
| 161 extra_params()->GetBoolean(extensionoptions::kAttributeAutoSize, | |
| 162 &auto_size_enabled); | |
| 163 | |
| 164 int max_height = 0; | |
| 165 int max_width = 0; | |
| 166 extra_params()->GetInteger(extensionoptions::kAttributeMaxHeight, | |
| 167 &max_height); | |
| 168 extra_params()->GetInteger(extensionoptions::kAttributeMaxWidth, &max_width); | |
| 169 | |
| 170 int min_height = 0; | |
| 171 int min_width = 0; | |
| 172 extra_params()->GetInteger(extensionoptions::kAttributeMinHeight, | |
| 173 &min_height); | |
| 174 extra_params()->GetInteger(extensionoptions::kAttributeMinWidth, &min_width); | |
| 175 | |
| 176 // Call SetAutoSize to apply all the appropriate validation and clipping of | |
| 177 // values. | |
| 178 SetAutoSize( | |
| 179 true, gfx::Size(min_width, min_height), gfx::Size(max_width, max_height)); | |
| 180 } | |
| OLD | NEW |