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/api/offscreen_tabs/offscreen_tabs_api.h" | 5 #include "chrome/browser/extensions/api/offscreen_tabs/offscreen_tabs_api.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/lazy_instance.h" |
12 #include "base/memory/linked_ptr.h" | 13 #include "base/memory/linked_ptr.h" |
13 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
14 #include "base/lazy_instance.h" | |
15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "chrome/browser/extensions/api/offscreen_tabs/offscreen_tabs_constants.
h" | 18 #include "chrome/browser/extensions/api/offscreen_tabs/offscreen_tabs_constants.
h" |
19 #include "chrome/browser/extensions/api/tabs/tabs.h" | 19 #include "chrome/browser/extensions/api/tabs/tabs.h" |
20 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 20 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
21 #include "chrome/browser/extensions/event_names.h" | 21 #include "chrome/browser/extensions/event_names.h" |
22 #include "chrome/browser/extensions/event_router.h" | 22 #include "chrome/browser/extensions/event_router.h" |
23 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 23 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
24 #include "chrome/browser/extensions/extension_service.h" | 24 #include "chrome/browser/extensions/extension_service.h" |
25 #include "chrome/browser/extensions/extension_system.h" | 25 #include "chrome/browser/extensions/extension_system.h" |
26 #include "chrome/browser/extensions/extension_tab_util.h" | 26 #include "chrome/browser/extensions/extension_tab_util.h" |
27 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
29 #include "chrome/browser/ui/browser_window.h" | 29 #include "chrome/browser/ui/browser_window.h" |
30 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 30 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
31 #include "chrome/browser/ui/window_sizer/window_sizer.h" | 31 #include "chrome/browser/ui/window_sizer/window_sizer.h" |
32 #include "chrome/common/chrome_notification_types.h" | 32 #include "chrome/common/chrome_notification_types.h" |
33 #include "chrome/common/extensions/extension.h" | 33 #include "chrome/common/extensions/extension.h" |
34 #include "chrome/common/extensions/extension_error_utils.h" | |
35 #include "chrome/common/extensions/extension_messages.h" | 34 #include "chrome/common/extensions/extension_messages.h" |
36 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
37 #include "chrome/common/url_constants.h" | 36 #include "chrome/common/url_constants.h" |
38 #include "content/public/browser/navigation_controller.h" | 37 #include "content/public/browser/navigation_controller.h" |
39 #include "content/public/browser/notification_details.h" | 38 #include "content/public/browser/notification_details.h" |
40 #include "content/public/browser/notification_source.h" | 39 #include "content/public/browser/notification_source.h" |
41 #include "content/public/browser/render_view_host.h" | 40 #include "content/public/browser/render_view_host.h" |
42 #include "content/public/browser/web_contents.h" | 41 #include "content/public/browser/web_contents.h" |
43 #include "content/public/browser/web_contents_view.h" | 42 #include "content/public/browser/web_contents_view.h" |
| 43 #include "extensions/common/error_utils.h" |
44 | 44 |
45 using content::NativeWebKeyboardEvent; | 45 using content::NativeWebKeyboardEvent; |
46 using content::NavigationController; | 46 using content::NavigationController; |
47 using content::NotificationDetails; | 47 using content::NotificationDetails; |
48 using content::NotificationSource; | 48 using content::NotificationSource; |
49 using content::WebContents; | 49 using content::WebContents; |
| 50 using extensions::ErrorUtils; |
50 using WebKit::WebInputEvent; | 51 using WebKit::WebInputEvent; |
51 | 52 |
52 namespace keys = extensions::offscreen_tabs_constants; | 53 namespace keys = extensions::offscreen_tabs_constants; |
53 namespace tabs_keys = extensions::tabs_constants; | 54 namespace tabs_keys = extensions::tabs_constants; |
54 namespace events = extensions::event_names; | 55 namespace events = extensions::event_names; |
55 | 56 |
56 // TODO(avi): Kill this when TabContents goes away. | 57 // TODO(avi): Kill this when TabContents goes away. |
57 class OffscreenTabContentsCreator { | 58 class OffscreenTabContentsCreator { |
58 public: | 59 public: |
59 static TabContents* CreateTabContents(content::WebContents* contents) { | 60 static TabContents* CreateTabContents(content::WebContents* contents) { |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 if (parent_tab) { | 353 if (parent_tab) { |
353 const OffscreenTabs& tabs = parent_tab->offscreen_tabs(); | 354 const OffscreenTabs& tabs = parent_tab->offscreen_tabs(); |
354 for (OffscreenTabs::const_iterator i = tabs.begin(); i != tabs.end(); ++i) { | 355 for (OffscreenTabs::const_iterator i = tabs.begin(); i != tabs.end(); ++i) { |
355 if ((*i)->GetID() == offscreen_tab_id) { | 356 if ((*i)->GetID() == offscreen_tab_id) { |
356 *offscreen_tab = *i; | 357 *offscreen_tab = *i; |
357 return true; | 358 return true; |
358 } | 359 } |
359 } | 360 } |
360 } | 361 } |
361 | 362 |
362 *error = ExtensionErrorUtils::FormatErrorMessage( | 363 *error = ErrorUtils::FormatErrorMessage( |
363 keys::kOffscreenTabNotFoundError, base::IntToString(offscreen_tab_id)); | 364 keys::kOffscreenTabNotFoundError, base::IntToString(offscreen_tab_id)); |
364 return false; | 365 return false; |
365 } | 366 } |
366 | 367 |
367 ParentTab* OffscreenTabMap::GetParentTab(WebContents* parent_contents, | 368 ParentTab* OffscreenTabMap::GetParentTab(WebContents* parent_contents, |
368 const std::string& extension_id) { | 369 const std::string& extension_id) { |
369 CHECK(parent_contents); | 370 CHECK(parent_contents); |
370 | 371 |
371 int parent_tab_id = ExtensionTabUtil::GetTabId(parent_contents); | 372 int parent_tab_id = ExtensionTabUtil::GetTabId(parent_contents); |
372 if (map_.find(parent_tab_id) == map_.end()) | 373 if (map_.find(parent_tab_id) == map_.end()) |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 DictionaryValue* create_props; | 467 DictionaryValue* create_props; |
467 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &create_props)); | 468 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &create_props)); |
468 | 469 |
469 std::string url_string; | 470 std::string url_string; |
470 EXTENSION_FUNCTION_VALIDATE(create_props->GetString( | 471 EXTENSION_FUNCTION_VALIDATE(create_props->GetString( |
471 tabs_keys::kUrlKey, &url_string)); | 472 tabs_keys::kUrlKey, &url_string)); |
472 | 473 |
473 GURL url = ExtensionTabUtil::ResolvePossiblyRelativeURL( | 474 GURL url = ExtensionTabUtil::ResolvePossiblyRelativeURL( |
474 url_string, GetExtension()); | 475 url_string, GetExtension()); |
475 if (!url.is_valid()) { | 476 if (!url.is_valid()) { |
476 error_ = ExtensionErrorUtils::FormatErrorMessage( | 477 error_ = ErrorUtils::FormatErrorMessage( |
477 tabs_keys::kInvalidUrlError, url_string); | 478 tabs_keys::kInvalidUrlError, url_string); |
478 return false; | 479 return false; |
479 } | 480 } |
480 | 481 |
481 if (ExtensionTabUtil::IsCrashURL(url)) { | 482 if (ExtensionTabUtil::IsCrashURL(url)) { |
482 error_ = tabs_keys::kNoCrashBrowserError; | 483 error_ = tabs_keys::kNoCrashBrowserError; |
483 return false; | 484 return false; |
484 } | 485 } |
485 | 486 |
486 gfx::Rect window_bounds; | 487 gfx::Rect window_bounds; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 GetOffscreenTabFunction::GetOffscreenTabFunction() {} | 534 GetOffscreenTabFunction::GetOffscreenTabFunction() {} |
534 GetOffscreenTabFunction::~GetOffscreenTabFunction() {} | 535 GetOffscreenTabFunction::~GetOffscreenTabFunction() {} |
535 | 536 |
536 bool GetOffscreenTabFunction::RunImpl() { | 537 bool GetOffscreenTabFunction::RunImpl() { |
537 int offscreen_tab_id; | 538 int offscreen_tab_id; |
538 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &offscreen_tab_id)); | 539 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &offscreen_tab_id)); |
539 | 540 |
540 OffscreenTab* offscreen_tab = NULL; | 541 OffscreenTab* offscreen_tab = NULL; |
541 if (!GetMap()->GetOffscreenTab( | 542 if (!GetMap()->GetOffscreenTab( |
542 offscreen_tab_id, this, &offscreen_tab, &error_)) { | 543 offscreen_tab_id, this, &offscreen_tab, &error_)) { |
543 error_ = ExtensionErrorUtils::FormatErrorMessage( | 544 error_ = ErrorUtils::FormatErrorMessage( |
544 keys::kOffscreenTabNotFoundError, base::IntToString(offscreen_tab_id)); | 545 keys::kOffscreenTabNotFoundError, base::IntToString(offscreen_tab_id)); |
545 return false; | 546 return false; |
546 } | 547 } |
547 | 548 |
548 SetResult(offscreen_tab->CreateValue()); | 549 SetResult(offscreen_tab->CreateValue()); |
549 return true; | 550 return true; |
550 } | 551 } |
551 | 552 |
552 GetAllOffscreenTabFunction::GetAllOffscreenTabFunction() {} | 553 GetAllOffscreenTabFunction::GetAllOffscreenTabFunction() {} |
553 GetAllOffscreenTabFunction::~GetAllOffscreenTabFunction() {} | 554 GetAllOffscreenTabFunction::~GetAllOffscreenTabFunction() {} |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 // async case (when a "javascript": URL is sent to a tab). | 841 // async case (when a "javascript": URL is sent to a tab). |
841 if (!is_async) | 842 if (!is_async) |
842 SendResponse(true); | 843 SendResponse(true); |
843 | 844 |
844 return true; | 845 return true; |
845 } | 846 } |
846 | 847 |
847 void UpdateOffscreenTabFunction::PopulateResult() { | 848 void UpdateOffscreenTabFunction::PopulateResult() { |
848 // There's no result associated with this callback. | 849 // There's no result associated with this callback. |
849 } | 850 } |
OLD | NEW |