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/tabs/tabs_api.h" | 5 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 #include "components/translate/core/common/language_detection_details.h" | 57 #include "components/translate/core/common/language_detection_details.h" |
58 #include "content/public/browser/navigation_controller.h" | 58 #include "content/public/browser/navigation_controller.h" |
59 #include "content/public/browser/navigation_entry.h" | 59 #include "content/public/browser/navigation_entry.h" |
60 #include "content/public/browser/notification_details.h" | 60 #include "content/public/browser/notification_details.h" |
61 #include "content/public/browser/notification_source.h" | 61 #include "content/public/browser/notification_source.h" |
62 #include "content/public/browser/render_process_host.h" | 62 #include "content/public/browser/render_process_host.h" |
63 #include "content/public/browser/render_view_host.h" | 63 #include "content/public/browser/render_view_host.h" |
64 #include "content/public/browser/render_widget_host_view.h" | 64 #include "content/public/browser/render_widget_host_view.h" |
65 #include "content/public/browser/web_contents.h" | 65 #include "content/public/browser/web_contents.h" |
66 #include "content/public/common/url_constants.h" | 66 #include "content/public/common/url_constants.h" |
67 #include "extensions/browser/api/capture_web_contents_function_impl.h" | |
68 #include "extensions/browser/app_window/app_window.h" | 67 #include "extensions/browser/app_window/app_window.h" |
69 #include "extensions/browser/extension_function_dispatcher.h" | 68 #include "extensions/browser/extension_function_dispatcher.h" |
70 #include "extensions/browser/extension_function_util.h" | 69 #include "extensions/browser/extension_function_util.h" |
71 #include "extensions/browser/extension_host.h" | 70 #include "extensions/browser/extension_host.h" |
72 #include "extensions/browser/file_reader.h" | 71 #include "extensions/browser/file_reader.h" |
73 #include "extensions/browser/script_executor.h" | 72 #include "extensions/browser/script_executor.h" |
74 #include "extensions/common/constants.h" | 73 #include "extensions/common/constants.h" |
75 #include "extensions/common/error_utils.h" | 74 #include "extensions/common/error_utils.h" |
76 #include "extensions/common/extension.h" | 75 #include "extensions/common/extension.h" |
77 #include "extensions/common/manifest_constants.h" | 76 #include "extensions/common/manifest_constants.h" |
(...skipping 20 matching lines...) Expand all Loading... |
98 using content::WebContents; | 97 using content::WebContents; |
99 | 98 |
100 namespace extensions { | 99 namespace extensions { |
101 | 100 |
102 namespace windows = api::windows; | 101 namespace windows = api::windows; |
103 namespace keys = tabs_constants; | 102 namespace keys = tabs_constants; |
104 namespace tabs = api::tabs; | 103 namespace tabs = api::tabs; |
105 | 104 |
106 using core_api::extension_types::InjectDetails; | 105 using core_api::extension_types::InjectDetails; |
107 | 106 |
108 template class CaptureWebContentsFunction<ChromeAsyncExtensionFunction>; | |
109 | |
110 namespace { | 107 namespace { |
111 | 108 |
112 bool GetBrowserFromWindowID(ChromeUIThreadExtensionFunction* function, | 109 bool GetBrowserFromWindowID(ChromeUIThreadExtensionFunction* function, |
113 int window_id, | 110 int window_id, |
114 Browser** browser) { | 111 Browser** browser) { |
115 std::string error; | 112 std::string error; |
116 Browser* result; | 113 Browser* result; |
117 result = | 114 result = |
118 ExtensionTabUtil::GetBrowserFromWindowID(function, window_id, &error); | 115 ExtensionTabUtil::GetBrowserFromWindowID(function, window_id, &error); |
119 if (!result) { | 116 if (!result) { |
120 function->SetError(error); | 117 function->SetError(error); |
121 return false; | 118 return false; |
122 } | 119 } |
123 | 120 |
124 *browser = result; | 121 *browser = result; |
125 return true; | 122 return true; |
126 } | 123 } |
127 | 124 |
| 125 bool GetBrowserFromWindowID(ExtensionFunction* function, |
| 126 const ChromeExtensionFunctionDetails& details, |
| 127 int window_id, |
| 128 Browser** browser) { |
| 129 std::string error; |
| 130 Browser* result; |
| 131 result = ExtensionTabUtil::GetBrowserFromWindowID( |
| 132 function, details, window_id, &error); |
| 133 if (!result) { |
| 134 function->SetError(error); |
| 135 return false; |
| 136 } |
| 137 |
| 138 *browser = result; |
| 139 return true; |
| 140 } |
| 141 |
128 // |error_message| can optionally be passed in and will be set with an | 142 // |error_message| can optionally be passed in and will be set with an |
129 // appropriate message if the tab cannot be found by id. | 143 // appropriate message if the tab cannot be found by id. |
130 bool GetTabById(int tab_id, | 144 bool GetTabById(int tab_id, |
131 Profile* profile, | 145 Profile* profile, |
132 bool include_incognito, | 146 bool include_incognito, |
133 Browser** browser, | 147 Browser** browser, |
134 TabStripModel** tab_strip, | 148 TabStripModel** tab_strip, |
135 content::WebContents** contents, | 149 content::WebContents** contents, |
136 int* tab_index, | 150 int* tab_index, |
137 std::string* error_message) { | 151 std::string* error_message) { |
(...skipping 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1491 return false; | 1505 return false; |
1492 } | 1506 } |
1493 // There's a chance that the tab is being dragged, or we're in some other | 1507 // There's a chance that the tab is being dragged, or we're in some other |
1494 // nested event loop. This code path ensures that the tab is safely closed | 1508 // nested event loop. This code path ensures that the tab is safely closed |
1495 // under such circumstances, whereas |TabStripModel::CloseWebContentsAt()| | 1509 // under such circumstances, whereas |TabStripModel::CloseWebContentsAt()| |
1496 // does not. | 1510 // does not. |
1497 contents->Close(); | 1511 contents->Close(); |
1498 return true; | 1512 return true; |
1499 } | 1513 } |
1500 | 1514 |
| 1515 TabsCaptureVisibleTabFunction::TabsCaptureVisibleTabFunction() |
| 1516 : chrome_details_(this) { |
| 1517 } |
| 1518 |
1501 bool TabsCaptureVisibleTabFunction::IsScreenshotEnabled() { | 1519 bool TabsCaptureVisibleTabFunction::IsScreenshotEnabled() { |
1502 PrefService* service = GetProfile()->GetPrefs(); | 1520 PrefService* service = chrome_details_.GetProfile()->GetPrefs(); |
1503 if (service->GetBoolean(prefs::kDisableScreenshots)) { | 1521 if (service->GetBoolean(prefs::kDisableScreenshots)) { |
1504 error_ = keys::kScreenshotsDisabled; | 1522 error_ = keys::kScreenshotsDisabled; |
1505 return false; | 1523 return false; |
1506 } | 1524 } |
1507 return true; | 1525 return true; |
1508 } | 1526 } |
1509 | 1527 |
1510 WebContents* TabsCaptureVisibleTabFunction::GetWebContentsForID(int window_id) { | 1528 WebContents* TabsCaptureVisibleTabFunction::GetWebContentsForID(int window_id) { |
1511 Browser* browser = NULL; | 1529 Browser* browser = NULL; |
1512 if (!GetBrowserFromWindowID(this, window_id, &browser)) | 1530 if (!GetBrowserFromWindowID(this, chrome_details_, window_id, &browser)) |
1513 return NULL; | 1531 return NULL; |
1514 | 1532 |
1515 WebContents* contents = browser->tab_strip_model()->GetActiveWebContents(); | 1533 WebContents* contents = browser->tab_strip_model()->GetActiveWebContents(); |
1516 if (!contents) { | 1534 if (!contents) { |
1517 error_ = keys::kInternalVisibleTabCaptureError; | 1535 error_ = keys::kInternalVisibleTabCaptureError; |
1518 return NULL; | 1536 return NULL; |
1519 } | 1537 } |
1520 | 1538 |
1521 if (!extension()->permissions_data()->CanCaptureVisiblePage( | 1539 if (!extension()->permissions_data()->CanCaptureVisiblePage( |
1522 SessionTabHelper::IdForTab(contents), &error_)) { | 1540 SessionTabHelper::IdForTab(contents), &error_)) { |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1897 ZoomController::ZoomMode zoom_mode = zoom_controller->zoom_mode(); | 1915 ZoomController::ZoomMode zoom_mode = zoom_controller->zoom_mode(); |
1898 api::tabs::ZoomSettings zoom_settings; | 1916 api::tabs::ZoomSettings zoom_settings; |
1899 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); | 1917 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); |
1900 | 1918 |
1901 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); | 1919 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); |
1902 SendResponse(true); | 1920 SendResponse(true); |
1903 return true; | 1921 return true; |
1904 } | 1922 } |
1905 | 1923 |
1906 } // namespace extensions | 1924 } // namespace extensions |
OLD | NEW |