| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/extension_tabs_module.h" | 5 #include "chrome/browser/extensions/extension_tabs_module.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted_memory.h" | 13 #include "base/memory/ref_counted_memory.h" |
| 13 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 14 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 15 #include "base/string16.h" | 16 #include "base/string16.h" |
| 16 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
| 17 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 18 #include "base/stringprintf.h" | 19 #include "base/stringprintf.h" |
| 19 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
| 20 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 21 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 21 #include "chrome/browser/extensions/extension_host.h" | 22 #include "chrome/browser/extensions/extension_host.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 32 #include "chrome/browser/ui/browser_list.h" | 33 #include "chrome/browser/ui/browser_list.h" |
| 33 #include "chrome/browser/ui/browser_navigator.h" | 34 #include "chrome/browser/ui/browser_navigator.h" |
| 34 #include "chrome/browser/ui/browser_window.h" | 35 #include "chrome/browser/ui/browser_window.h" |
| 35 #include "chrome/browser/ui/panels/panel_manager.h" | 36 #include "chrome/browser/ui/panels/panel_manager.h" |
| 36 #include "chrome/browser/ui/snapshot_tab_helper.h" | 37 #include "chrome/browser/ui/snapshot_tab_helper.h" |
| 37 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 38 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 38 #include "chrome/browser/ui/window_sizer.h" | 39 #include "chrome/browser/ui/window_sizer.h" |
| 39 #include "chrome/browser/web_applications/web_app.h" | 40 #include "chrome/browser/web_applications/web_app.h" |
| 40 #include "chrome/common/chrome_notification_types.h" | 41 #include "chrome/common/chrome_notification_types.h" |
| 41 #include "chrome/common/chrome_switches.h" | 42 #include "chrome/common/chrome_switches.h" |
| 43 #include "chrome/common/extensions/api/windows.h" |
| 42 #include "chrome/common/extensions/extension.h" | 44 #include "chrome/common/extensions/extension.h" |
| 43 #include "chrome/common/extensions/extension_error_utils.h" | 45 #include "chrome/common/extensions/extension_error_utils.h" |
| 44 #include "chrome/common/extensions/extension_messages.h" | 46 #include "chrome/common/extensions/extension_messages.h" |
| 45 #include "chrome/common/pref_names.h" | 47 #include "chrome/common/pref_names.h" |
| 46 #include "chrome/common/url_constants.h" | 48 #include "chrome/common/url_constants.h" |
| 47 #include "content/browser/renderer_host/backing_store.h" | 49 #include "content/browser/renderer_host/backing_store.h" |
| 48 #include "content/browser/renderer_host/render_view_host.h" | 50 #include "content/browser/renderer_host/render_view_host.h" |
| 49 #include "content/public/browser/navigation_controller.h" | 51 #include "content/public/browser/navigation_controller.h" |
| 50 #include "content/public/browser/navigation_entry.h" | 52 #include "content/public/browser/navigation_entry.h" |
| 51 #include "content/public/browser/notification_details.h" | 53 #include "content/public/browser/notification_details.h" |
| 52 #include "content/public/browser/notification_source.h" | 54 #include "content/public/browser/notification_source.h" |
| 53 #include "content/public/browser/render_view_host_delegate.h" | 55 #include "content/public/browser/render_view_host_delegate.h" |
| 54 #include "content/public/browser/web_contents.h" | 56 #include "content/public/browser/web_contents.h" |
| 55 #include "content/public/browser/web_contents_view.h" | 57 #include "content/public/browser/web_contents_view.h" |
| 56 #include "skia/ext/image_operations.h" | 58 #include "skia/ext/image_operations.h" |
| 57 #include "skia/ext/platform_canvas.h" | 59 #include "skia/ext/platform_canvas.h" |
| 58 #include "third_party/skia/include/core/SkBitmap.h" | 60 #include "third_party/skia/include/core/SkBitmap.h" |
| 59 #include "ui/gfx/codec/jpeg_codec.h" | 61 #include "ui/gfx/codec/jpeg_codec.h" |
| 60 #include "ui/gfx/codec/png_codec.h" | 62 #include "ui/gfx/codec/png_codec.h" |
| 61 | 63 |
| 62 namespace keys = extension_tabs_module_constants; | 64 namespace keys = extension_tabs_module_constants; |
| 63 namespace errors = extension_manifest_errors; | 65 namespace errors = extension_manifest_errors; |
| 64 | 66 |
| 65 using content::NavigationController; | 67 using content::NavigationController; |
| 66 using content::NavigationEntry; | 68 using content::NavigationEntry; |
| 67 using content::OpenURLParams; | 69 using content::OpenURLParams; |
| 68 using content::Referrer; | 70 using content::Referrer; |
| 69 using content::WebContents; | 71 using content::WebContents; |
| 72 using namespace extensions::api::windows; |
| 70 | 73 |
| 71 const int CaptureVisibleTabFunction::kDefaultQuality = 90; | 74 const int CaptureVisibleTabFunction::kDefaultQuality = 90; |
| 72 | 75 |
| 73 namespace { | 76 namespace { |
| 74 | 77 |
| 75 // |error_message| can optionally be passed in a will be set with an appropriate | 78 // |error_message| can optionally be passed in a will be set with an appropriate |
| 76 // message if the window cannot be found by id. | 79 // message if the window cannot be found by id. |
| 77 Browser* GetBrowserInProfileWithId(Profile* profile, | 80 Browser* GetBrowserInProfileWithId(Profile* profile, |
| 78 const int window_id, | 81 const int window_id, |
| 79 bool include_incognito, | 82 bool include_incognito, |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 return value ? MATCH_TRUE : MATCH_FALSE; | 211 return value ? MATCH_TRUE : MATCH_FALSE; |
| 209 } | 212 } |
| 210 return NOT_SET; | 213 return NOT_SET; |
| 211 } | 214 } |
| 212 | 215 |
| 213 } // namespace | 216 } // namespace |
| 214 | 217 |
| 215 // Windows --------------------------------------------------------------------- | 218 // Windows --------------------------------------------------------------------- |
| 216 | 219 |
| 217 bool GetWindowFunction::RunImpl() { | 220 bool GetWindowFunction::RunImpl() { |
| 218 int window_id = extension_misc::kUnknownWindowId; | 221 scoped_ptr<Get::Params> params(Get::Params::Create(*args_)); |
| 219 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); | 222 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 220 | 223 |
| 221 bool populate_tabs = false; | 224 bool populate_tabs = false; |
| 222 if (HasOptionalArgument(1)) { | 225 if (params->get_info.get() && params->get_info->populate.get()) |
| 223 DictionaryValue* args = NULL; | 226 populate_tabs = *params->get_info->populate; |
| 224 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &args)); | |
| 225 | |
| 226 if (args->HasKey(keys::kPopulateKey)) { | |
| 227 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kPopulateKey, | |
| 228 &populate_tabs)); | |
| 229 } | |
| 230 } | |
| 231 | 227 |
| 232 Browser* browser = NULL; | 228 Browser* browser = NULL; |
| 233 if (!GetBrowserFromWindowID(this, window_id, &browser)) | 229 if (!GetBrowserFromWindowID(this, params->window_id, &browser)) |
| 234 return false; | 230 return false; |
| 235 | 231 |
| 236 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs)); | 232 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs)); |
| 237 return true; | 233 return true; |
| 238 } | 234 } |
| 239 | 235 |
| 240 bool GetCurrentWindowFunction::RunImpl() { | 236 bool GetCurrentWindowFunction::RunImpl() { |
| 237 scoped_ptr<GetCurrent::Params> params(GetCurrent::Params::Create(*args_)); |
| 238 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 239 |
| 241 bool populate_tabs = false; | 240 bool populate_tabs = false; |
| 242 if (HasOptionalArgument(0)) { | 241 if (params->get_info.get() && params->get_info->populate.get()) |
| 243 DictionaryValue* args = NULL; | 242 populate_tabs = *params->get_info->populate; |
| 244 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | |
| 245 | |
| 246 if (args->HasKey(keys::kPopulateKey)) { | |
| 247 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kPopulateKey, | |
| 248 &populate_tabs)); | |
| 249 } | |
| 250 } | |
| 251 | 243 |
| 252 Browser* browser = GetCurrentBrowser(); | 244 Browser* browser = GetCurrentBrowser(); |
| 253 if (!browser || !browser->window()) { | 245 if (!browser || !browser->window()) { |
| 254 error_ = keys::kNoCurrentWindowError; | 246 error_ = keys::kNoCurrentWindowError; |
| 255 return false; | 247 return false; |
| 256 } | 248 } |
| 257 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs)); | 249 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs)); |
| 258 return true; | 250 return true; |
| 259 } | 251 } |
| 260 | 252 |
| 261 bool GetLastFocusedWindowFunction::RunImpl() { | 253 bool GetLastFocusedWindowFunction::RunImpl() { |
| 254 scoped_ptr<GetLastFocused::Params> params(GetLastFocused::Params::Create(*args
_)); |
| 255 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 256 |
| 262 bool populate_tabs = false; | 257 bool populate_tabs = false; |
| 263 if (HasOptionalArgument(0)) { | 258 if (params->get_info.get() && params->get_info->populate.get()) |
| 264 DictionaryValue* args = NULL; | 259 populate_tabs = *params->get_info->populate; |
| 265 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | |
| 266 | |
| 267 if (args->HasKey(keys::kPopulateKey)) { | |
| 268 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kPopulateKey, | |
| 269 &populate_tabs)); | |
| 270 } | |
| 271 } | |
| 272 | 260 |
| 273 Browser* browser = BrowserList::FindAnyBrowser( | 261 Browser* browser = BrowserList::FindAnyBrowser( |
| 274 profile(), include_incognito()); | 262 profile(), include_incognito()); |
| 275 if (!browser || !browser->window()) { | 263 if (!browser || !browser->window()) { |
| 276 error_ = keys::kNoLastFocusedWindowError; | 264 error_ = keys::kNoLastFocusedWindowError; |
| 277 return false; | 265 return false; |
| 278 } | 266 } |
| 279 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs)); | 267 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs)); |
| 280 return true; | 268 return true; |
| 281 } | 269 } |
| (...skipping 1423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1705 // called for every API call the extension made. | 1693 // called for every API call the extension made. |
| 1706 GotLanguage(language); | 1694 GotLanguage(language); |
| 1707 } | 1695 } |
| 1708 | 1696 |
| 1709 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1697 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
| 1710 result_.reset(Value::CreateStringValue(language.c_str())); | 1698 result_.reset(Value::CreateStringValue(language.c_str())); |
| 1711 SendResponse(true); | 1699 SendResponse(true); |
| 1712 | 1700 |
| 1713 Release(); // Balanced in Run() | 1701 Release(); // Balanced in Run() |
| 1714 } | 1702 } |
| OLD | NEW |