Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: chrome/browser/extensions/extension_tabs_module.cc

Issue 9309044: Supporting more APIs with json_schema_compiler (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: support for choices Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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(
255 GetLastFocused::Params::Create(*args_));
256 EXTENSION_FUNCTION_VALIDATE(params.get());
257
262 bool populate_tabs = false; 258 bool populate_tabs = false;
263 if (HasOptionalArgument(0)) { 259 if (params->get_info.get() && params->get_info->populate.get())
264 DictionaryValue* args = NULL; 260 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 261
273 Browser* browser = BrowserList::FindAnyBrowser( 262 Browser* browser = BrowserList::FindAnyBrowser(
274 profile(), include_incognito()); 263 profile(), include_incognito());
275 if (!browser || !browser->window()) { 264 if (!browser || !browser->window()) {
276 error_ = keys::kNoLastFocusedWindowError; 265 error_ = keys::kNoLastFocusedWindowError;
277 return false; 266 return false;
278 } 267 }
279 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs)); 268 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, populate_tabs));
280 return true; 269 return true;
281 } 270 }
282 271
283 bool GetAllWindowsFunction::RunImpl() { 272 bool GetAllWindowsFunction::RunImpl() {
273 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(*args_));
274 EXTENSION_FUNCTION_VALIDATE(params.get());
275
284 bool populate_tabs = false; 276 bool populate_tabs = false;
285 if (HasOptionalArgument(0)) { 277 if (params->get_info.get() && params->get_info->populate.get())
286 DictionaryValue* args = NULL; 278 populate_tabs = *params->get_info->populate;
287 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
288
289 if (args->HasKey(keys::kPopulateKey)) {
290 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kPopulateKey,
291 &populate_tabs));
292 }
293 }
294 279
295 result_.reset(new ListValue()); 280 result_.reset(new ListValue());
296 Profile* incognito_profile = 281 Profile* incognito_profile =
297 include_incognito() && profile()->HasOffTheRecordProfile() ? 282 include_incognito() && profile()->HasOffTheRecordProfile() ?
298 profile()->GetOffTheRecordProfile() : NULL; 283 profile()->GetOffTheRecordProfile() : NULL;
299 for (BrowserList::const_iterator browser = BrowserList::begin(); 284 for (BrowserList::const_iterator browser = BrowserList::begin();
300 browser != BrowserList::end(); ++browser) { 285 browser != BrowserList::end(); ++browser) {
301 // Only examine browsers in the current profile that have windows. 286 // Only examine browsers in the current profile that have windows.
302 if (((*browser)->profile() == profile() || 287 if (((*browser)->profile() == profile() ||
303 (*browser)->profile() == incognito_profile) && 288 (*browser)->profile() == incognito_profile) &&
(...skipping 1401 matching lines...) Expand 10 before | Expand all | Expand 10 after
1705 // called for every API call the extension made. 1690 // called for every API call the extension made.
1706 GotLanguage(language); 1691 GotLanguage(language);
1707 } 1692 }
1708 1693
1709 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { 1694 void DetectTabLanguageFunction::GotLanguage(const std::string& language) {
1710 result_.reset(Value::CreateStringValue(language.c_str())); 1695 result_.reset(Value::CreateStringValue(language.c_str()));
1711 SendResponse(true); 1696 SendResponse(true);
1712 1697
1713 Release(); // Balanced in Run() 1698 Release(); // Balanced in Run()
1714 } 1699 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698