| 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/extensions/extension_tab_util.h" | 9 #include "chrome/browser/extensions/extension_tab_util.h" |
| 10 #include "chrome/browser/guest_view/extension_options/extension_options_constant
s.h" | 10 #include "chrome/browser/guest_view/extension_options/extension_options_constant
s.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 128 } |
| 129 | 129 |
| 130 const char* ExtensionOptionsGuest::GetAPINamespace() const { | 130 const char* ExtensionOptionsGuest::GetAPINamespace() const { |
| 131 return extensionoptions::kAPINamespace; | 131 return extensionoptions::kAPINamespace; |
| 132 } | 132 } |
| 133 | 133 |
| 134 int ExtensionOptionsGuest::GetTaskPrefix() const { | 134 int ExtensionOptionsGuest::GetTaskPrefix() const { |
| 135 return IDS_EXTENSION_TASK_MANAGER_EXTENSIONOPTIONS_TAG_PREFIX; | 135 return IDS_EXTENSION_TASK_MANAGER_EXTENSIONOPTIONS_TAG_PREFIX; |
| 136 } | 136 } |
| 137 | 137 |
| 138 content::WebContents* ExtensionOptionsGuest::GetAssociatedWebContents() const { | |
| 139 return guest_web_contents(); | |
| 140 } | |
| 141 | |
| 142 bool ExtensionOptionsGuest::OnMessageReceived(const IPC::Message& message) { | |
| 143 bool handled = true; | |
| 144 IPC_BEGIN_MESSAGE_MAP(ExtensionOptionsGuest, message) | |
| 145 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | |
| 146 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 147 IPC_END_MESSAGE_MAP() | |
| 148 return handled; | |
| 149 } | |
| 150 | |
| 151 void ExtensionOptionsGuest::OnRequest( | |
| 152 const ExtensionHostMsg_Request_Params& params) { | |
| 153 extension_function_dispatcher_->Dispatch( | |
| 154 params, guest_web_contents()->GetRenderViewHost()); | |
| 155 } | |
| 156 | |
| 157 void ExtensionOptionsGuest::GuestSizeChangedDueToAutoSize( | 138 void ExtensionOptionsGuest::GuestSizeChangedDueToAutoSize( |
| 158 const gfx::Size& old_size, | 139 const gfx::Size& old_size, |
| 159 const gfx::Size& new_size) { | 140 const gfx::Size& new_size) { |
| 160 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 141 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 161 args->SetInteger(extensionoptions::kNewWidth, new_size.width()); | 142 args->SetInteger(extensionoptions::kNewWidth, new_size.width()); |
| 162 args->SetInteger(extensionoptions::kNewHeight, new_size.height()); | 143 args->SetInteger(extensionoptions::kNewHeight, new_size.height()); |
| 163 args->SetInteger(extensionoptions::kOldWidth, old_size.width()); | 144 args->SetInteger(extensionoptions::kOldWidth, old_size.width()); |
| 164 args->SetInteger(extensionoptions::kOldHeight, old_size.height()); | 145 args->SetInteger(extensionoptions::kOldHeight, old_size.height()); |
| 165 DispatchEventToEmbedder(new extensions::GuestViewBase::Event( | 146 DispatchEventToEmbedder(new extensions::GuestViewBase::Event( |
| 166 extension_options_internal::OnSizeChanged::kEventName, args.Pass())); | 147 extension_options_internal::OnSizeChanged::kEventName, args.Pass())); |
| 167 } | 148 } |
| 168 | 149 |
| 169 bool ExtensionOptionsGuest::IsAutoSizeSupported() const { | 150 bool ExtensionOptionsGuest::IsAutoSizeSupported() const { |
| 170 return true; | 151 return true; |
| 171 } | 152 } |
| 172 | 153 |
| 173 void ExtensionOptionsGuest::SetUpAutoSize() { | 154 content::WebContents* ExtensionOptionsGuest::GetAssociatedWebContents() const { |
| 174 // Read the autosize parameters passed in from the embedder. | 155 return guest_web_contents(); |
| 175 bool auto_size_enabled = false; | |
| 176 attach_params()->GetBoolean(extensionoptions::kAttributeAutoSize, | |
| 177 &auto_size_enabled); | |
| 178 | |
| 179 int max_height = 0; | |
| 180 int max_width = 0; | |
| 181 attach_params()->GetInteger(extensionoptions::kAttributeMaxHeight, | |
| 182 &max_height); | |
| 183 attach_params()->GetInteger(extensionoptions::kAttributeMaxWidth, &max_width); | |
| 184 | |
| 185 int min_height = 0; | |
| 186 int min_width = 0; | |
| 187 attach_params()->GetInteger(extensionoptions::kAttributeMinHeight, | |
| 188 &min_height); | |
| 189 attach_params()->GetInteger(extensionoptions::kAttributeMinWidth, &min_width); | |
| 190 | |
| 191 // Call SetAutoSize to apply all the appropriate validation and clipping of | |
| 192 // values. | |
| 193 SetAutoSize( | |
| 194 true, gfx::Size(min_width, min_height), gfx::Size(max_width, max_height)); | |
| 195 } | 156 } |
| 196 | 157 |
| 197 void ExtensionOptionsGuest::CloseContents(content::WebContents* source) { | 158 void ExtensionOptionsGuest::CloseContents(content::WebContents* source) { |
| 198 DispatchEventToEmbedder(new extensions::GuestViewBase::Event( | 159 DispatchEventToEmbedder(new extensions::GuestViewBase::Event( |
| 199 extension_options_internal::OnClose::kEventName, | 160 extension_options_internal::OnClose::kEventName, |
| 200 make_scoped_ptr(new base::DictionaryValue()))); | 161 make_scoped_ptr(new base::DictionaryValue()))); |
| 201 } | 162 } |
| 202 | 163 |
| 203 bool ExtensionOptionsGuest::HandleContextMenu( | 164 bool ExtensionOptionsGuest::HandleContextMenu( |
| 204 const content::ContextMenuParams& params) { | 165 const content::ContextMenuParams& params) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 230 content::OpenURLParams params(target_url, | 191 content::OpenURLParams params(target_url, |
| 231 content::Referrer(), | 192 content::Referrer(), |
| 232 NEW_FOREGROUND_TAB, | 193 NEW_FOREGROUND_TAB, |
| 233 content::PAGE_TRANSITION_LINK, | 194 content::PAGE_TRANSITION_LINK, |
| 234 false); | 195 false); |
| 235 browser->OpenURL(params); | 196 browser->OpenURL(params); |
| 236 // TODO(ericzeng): Open the tab in the background if the click was a | 197 // TODO(ericzeng): Open the tab in the background if the click was a |
| 237 // ctrl-click or middle mouse button click | 198 // ctrl-click or middle mouse button click |
| 238 return false; | 199 return false; |
| 239 } | 200 } |
| 201 |
| 202 bool ExtensionOptionsGuest::OnMessageReceived(const IPC::Message& message) { |
| 203 bool handled = true; |
| 204 IPC_BEGIN_MESSAGE_MAP(ExtensionOptionsGuest, message) |
| 205 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
| 206 IPC_MESSAGE_UNHANDLED(handled = false) |
| 207 IPC_END_MESSAGE_MAP() |
| 208 return handled; |
| 209 } |
| 210 |
| 211 void ExtensionOptionsGuest::OnRequest( |
| 212 const ExtensionHostMsg_Request_Params& params) { |
| 213 extension_function_dispatcher_->Dispatch( |
| 214 params, guest_web_contents()->GetRenderViewHost()); |
| 215 } |
| 216 |
| 217 void ExtensionOptionsGuest::SetUpAutoSize() { |
| 218 // Read the autosize parameters passed in from the embedder. |
| 219 bool auto_size_enabled = false; |
| 220 attach_params()->GetBoolean(extensionoptions::kAttributeAutoSize, |
| 221 &auto_size_enabled); |
| 222 |
| 223 int max_height = 0; |
| 224 int max_width = 0; |
| 225 attach_params()->GetInteger(extensionoptions::kAttributeMaxHeight, |
| 226 &max_height); |
| 227 attach_params()->GetInteger(extensionoptions::kAttributeMaxWidth, &max_width); |
| 228 |
| 229 int min_height = 0; |
| 230 int min_width = 0; |
| 231 attach_params()->GetInteger(extensionoptions::kAttributeMinHeight, |
| 232 &min_height); |
| 233 attach_params()->GetInteger(extensionoptions::kAttributeMinWidth, &min_width); |
| 234 |
| 235 // Call SetAutoSize to apply all the appropriate validation and clipping of |
| 236 // values. |
| 237 SetAutoSize(auto_size_enabled, |
| 238 gfx::Size(min_width, min_height), |
| 239 gfx::Size(max_width, max_height)); |
| 240 } |
| OLD | NEW |