Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| (...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 946 | 946 |
| 947 // Close the tab in this convoluted way, since there's a chance that the tab | 947 // Close the tab in this convoluted way, since there's a chance that the tab |
| 948 // is being dragged, or we're in some other nested event loop. This code path | 948 // is being dragged, or we're in some other nested event loop. This code path |
| 949 // should ensure that the tab is safely closed under such circumstances, | 949 // should ensure that the tab is safely closed under such circumstances, |
| 950 // whereas |Browser::CloseTabContents()| does not. | 950 // whereas |Browser::CloseTabContents()| does not. |
| 951 RenderViewHost* render_view_host = contents->render_view_host(); | 951 RenderViewHost* render_view_host = contents->render_view_host(); |
| 952 render_view_host->delegate()->Close(render_view_host); | 952 render_view_host->delegate()->Close(render_view_host); |
| 953 return true; | 953 return true; |
| 954 } | 954 } |
| 955 | 955 |
| 956 bool SetZoomPercentTabFunction::RunImpl() { | |
| 957 int tab_id; | |
| 958 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); | |
| 959 | |
| 960 double zoom_percent = 0; | |
| 961 if (!args_->GetDouble(1, &zoom_percent)) { | |
| 962 int int_zoom_percent = 0; | |
| 963 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &int_zoom_percent)); | |
|
Aaron Boodman
2011/02/07 09:26:55
The renderer can never legitimately send anything
| |
| 964 zoom_percent = int_zoom_percent; | |
| 965 } | |
| 966 EXTENSION_FUNCTION_VALIDATE(zoom_percent >= 0); | |
|
Aaron Boodman
2011/02/07 09:26:55
Same here (had to fix a bug in json_schema.js firs
| |
| 967 | |
| 968 Browser* browser = NULL; | |
| 969 TabContentsWrapper* contents = NULL; | |
| 970 if (!GetTabById(tab_id, profile(), include_incognito(), | |
| 971 &browser, NULL, &contents, NULL, &error_)) { | |
| 972 return false; | |
| 973 } | |
| 974 | |
| 975 // Store the tab id for later | |
| 976 tab_id_ = tab_id; | |
| 977 | |
| 978 request_id_ = contents->tab_contents()->SetZoomPercent(zoom_percent); | |
| 979 | |
| 980 // Need to wait until the render process responds to the request | |
| 981 // before we can respond to the extension request. | |
| 982 registrar_.Add(this, | |
| 983 NotificationType::ZOOM_LEVEL_CHANGED, | |
| 984 NotificationService::AllSources()); | |
| 985 AddRef(); // Balanced in SetZoomPercentTabFunction::Observe(). | |
| 986 | |
| 987 return true; | |
| 988 } | |
| 989 | |
| 990 void SetZoomPercentTabFunction::Observe(NotificationType type, | |
| 991 const NotificationSource& source, | |
| 992 const NotificationDetails& details) { | |
| 993 CHECK(type == NotificationType::ZOOM_LEVEL_CHANGED); | |
|
Aaron Boodman
2011/02/07 09:26:55
I prefer CHECK to DCHECK since it will generate cr
| |
| 994 | |
| 995 // Wait for our specific request | |
| 996 int observed_request_id = *Details<int>(details).ptr(); | |
| 997 if (observed_request_id != request_id_) | |
| 998 return; | |
| 999 | |
| 1000 Browser* browser = NULL; | |
| 1001 TabContentsWrapper* contents = NULL; | |
| 1002 if (!GetTabById(tab_id_, profile(), include_incognito(), | |
| 1003 &browser, NULL, &contents, NULL, &error_)) { | |
| 1004 Release(); // Balanced in SetZoomPercentTabFunction::RunImpl | |
| 1005 return; | |
| 1006 } | |
| 1007 | |
| 1008 bool enable_inc_ignored = false; | |
| 1009 bool enable_dec_ignored = false; | |
| 1010 double zoom_percent = contents->tab_contents()->GetZoomPercent( | |
| 1011 &enable_inc_ignored, &enable_dec_ignored); | |
| 1012 | |
| 1013 result_.reset(Value::CreateDoubleValue(zoom_percent)); | |
| 1014 SendResponse(true); | |
| 1015 Release(); // Balanced in SetZoomPercentTabFunction::RunImpl | |
| 1016 } | |
| 1017 | |
| 1018 bool GetZoomPercentTabFunction::RunImpl() { | |
| 1019 int tab_id; | |
| 1020 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); | |
| 1021 | |
| 1022 Browser* browser = NULL; | |
| 1023 TabContentsWrapper* contents = NULL; | |
| 1024 if (!GetTabById(tab_id, profile(), include_incognito(), | |
| 1025 &browser, NULL, &contents, NULL, &error_)) { | |
| 1026 return false; | |
| 1027 } | |
| 1028 | |
| 1029 bool enable_inc_ignored; | |
| 1030 bool enable_dec_ignored; | |
| 1031 double zoom_percent = contents->tab_contents()->GetZoomPercent( | |
| 1032 &enable_inc_ignored, &enable_dec_ignored); | |
| 1033 | |
| 1034 result_.reset(Value::CreateDoubleValue(zoom_percent)); | |
| 1035 return true; | |
| 1036 } | |
| 1037 | |
| 956 bool CaptureVisibleTabFunction::RunImpl() { | 1038 bool CaptureVisibleTabFunction::RunImpl() { |
| 957 Browser* browser; | 1039 Browser* browser; |
| 958 // windowId defaults to "current" window. | 1040 // windowId defaults to "current" window. |
| 959 int window_id = -1; | 1041 int window_id = -1; |
| 960 | 1042 |
| 961 if (HasOptionalArgument(0)) { | 1043 if (HasOptionalArgument(0)) { |
| 962 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); | 1044 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); |
| 963 browser = GetBrowserInProfileWithId(profile(), window_id, | 1045 browser = GetBrowserInProfileWithId(profile(), window_id, |
| 964 include_incognito(), &error_); | 1046 include_incognito(), &error_); |
| 965 } else { | 1047 } else { |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1241 } | 1323 } |
| 1242 | 1324 |
| 1243 static GURL ResolvePossiblyRelativeURL(std::string url_string, | 1325 static GURL ResolvePossiblyRelativeURL(std::string url_string, |
| 1244 const Extension* extension) { | 1326 const Extension* extension) { |
| 1245 GURL url = GURL(url_string); | 1327 GURL url = GURL(url_string); |
| 1246 if (!url.is_valid()) | 1328 if (!url.is_valid()) |
| 1247 url = extension->GetResourceURL(url_string); | 1329 url = extension->GetResourceURL(url_string); |
| 1248 | 1330 |
| 1249 return url; | 1331 return url; |
| 1250 } | 1332 } |
| OLD | NEW |