| 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/activity_log/activity_log.h" | 5 #include "chrome/browser/extensions/activity_log/activity_log.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/json/json_string_value_serializer.h" | 13 #include "base/json/json_string_value_serializer.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" |
| 17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
| 20 #include "base/threading/thread_checker.h" | 21 #include "base/threading/thread_checker.h" |
| 22 #include "base/values.h" |
| 21 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/chrome_notification_types.h" | 24 #include "chrome/browser/chrome_notification_types.h" |
| 23 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" | 25 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" |
| 24 #include "chrome/browser/extensions/activity_log/counting_policy.h" | 26 #include "chrome/browser/extensions/activity_log/counting_policy.h" |
| 25 #include "chrome/browser/extensions/activity_log/fullstream_ui_policy.h" | 27 #include "chrome/browser/extensions/activity_log/fullstream_ui_policy.h" |
| 26 #include "chrome/browser/extensions/api/activity_log_private/activity_log_privat
e_api.h" | 28 #include "chrome/browser/extensions/api/activity_log_private/activity_log_privat
e_api.h" |
| 27 #include "chrome/browser/extensions/extension_tab_util.h" | 29 #include "chrome/browser/extensions/extension_tab_util.h" |
| 28 #include "chrome/browser/prerender/prerender_manager.h" | 30 #include "chrome/browser/prerender/prerender_manager.h" |
| 29 #include "chrome/browser/prerender/prerender_manager_factory.h" | 31 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 30 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 bool arg_incognito = action->page_incognito(); | 272 bool arg_incognito = action->page_incognito(); |
| 271 | 273 |
| 272 switch (api_info->arg_url_transform) { | 274 switch (api_info->arg_url_transform) { |
| 273 case NONE: { | 275 case NONE: { |
| 274 // No translation needed; just extract the URL directly from a raw string | 276 // No translation needed; just extract the URL directly from a raw string |
| 275 // or from a dictionary. Succeeds if we can find a string in the | 277 // or from a dictionary. Succeeds if we can find a string in the |
| 276 // argument list and that the string resolves to a valid URL. | 278 // argument list and that the string resolves to a valid URL. |
| 277 std::string url_string; | 279 std::string url_string; |
| 278 if (action->args()->GetString(url_index, &url_string) && | 280 if (action->args()->GetString(url_index, &url_string) && |
| 279 ResolveUrl(action->page_url(), url_string, &arg_url)) { | 281 ResolveUrl(action->page_url(), url_string, &arg_url)) { |
| 280 action->mutable_args()->Set(url_index, | 282 action->mutable_args()->Set( |
| 281 new base::Value(kArgUrlPlaceholder)); | 283 url_index, base::MakeUnique<base::Value>(kArgUrlPlaceholder)); |
| 282 } | 284 } |
| 283 break; | 285 break; |
| 284 } | 286 } |
| 285 | 287 |
| 286 case DICT_LOOKUP: { | 288 case DICT_LOOKUP: { |
| 287 CHECK(api_info->arg_url_dict_path); | 289 CHECK(api_info->arg_url_dict_path); |
| 288 // Look up the URL from a dictionary at the specified location. Succeeds | 290 // Look up the URL from a dictionary at the specified location. Succeeds |
| 289 // if we can find a dictionary in the argument list, the dictionary | 291 // if we can find a dictionary in the argument list, the dictionary |
| 290 // contains the specified key, and the corresponding value resolves to a | 292 // contains the specified key, and the corresponding value resolves to a |
| 291 // valid URL. | 293 // valid URL. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 302 case LOOKUP_TAB_ID: { | 304 case LOOKUP_TAB_ID: { |
| 303 // Translation of tab IDs to URLs has been requested. There are two | 305 // Translation of tab IDs to URLs has been requested. There are two |
| 304 // cases to consider: either a single integer or a list of integers (when | 306 // cases to consider: either a single integer or a list of integers (when |
| 305 // multiple tabs are manipulated). | 307 // multiple tabs are manipulated). |
| 306 int tab_id; | 308 int tab_id; |
| 307 base::ListValue* tab_list = NULL; | 309 base::ListValue* tab_list = NULL; |
| 308 if (action->args()->GetInteger(url_index, &tab_id)) { | 310 if (action->args()->GetInteger(url_index, &tab_id)) { |
| 309 // Single tab ID to translate. | 311 // Single tab ID to translate. |
| 310 GetUrlForTabId(tab_id, profile, &arg_url, &arg_incognito); | 312 GetUrlForTabId(tab_id, profile, &arg_url, &arg_incognito); |
| 311 if (arg_url.is_valid()) { | 313 if (arg_url.is_valid()) { |
| 312 action->mutable_args()->Set(url_index, | 314 action->mutable_args()->Set( |
| 313 new base::Value(kArgUrlPlaceholder)); | 315 url_index, base::MakeUnique<base::Value>(kArgUrlPlaceholder)); |
| 314 } | 316 } |
| 315 } else if (action->mutable_args()->GetList(url_index, &tab_list)) { | 317 } else if (action->mutable_args()->GetList(url_index, &tab_list)) { |
| 316 // A list of possible IDs to translate. Work through in reverse order | 318 // A list of possible IDs to translate. Work through in reverse order |
| 317 // so the last one translated is left in arg_url. | 319 // so the last one translated is left in arg_url. |
| 318 int extracted_index = -1; // Which list item is copied to arg_url? | 320 int extracted_index = -1; // Which list item is copied to arg_url? |
| 319 for (int i = tab_list->GetSize() - 1; i >= 0; --i) { | 321 for (int i = tab_list->GetSize() - 1; i >= 0; --i) { |
| 320 if (tab_list->GetInteger(i, &tab_id) && | 322 if (tab_list->GetInteger(i, &tab_id) && |
| 321 GetUrlForTabId(tab_id, profile, &arg_url, &arg_incognito)) { | 323 GetUrlForTabId(tab_id, profile, &arg_url, &arg_incognito)) { |
| 322 if (!arg_incognito) | 324 if (!arg_incognito) |
| 323 tab_list->Set(i, new base::Value(arg_url.spec())); | 325 tab_list->Set(i, base::MakeUnique<base::Value>(arg_url.spec())); |
| 324 extracted_index = i; | 326 extracted_index = i; |
| 325 } | 327 } |
| 326 } | 328 } |
| 327 if (extracted_index >= 0) { | 329 if (extracted_index >= 0) { |
| 328 tab_list->Set(extracted_index, new base::Value(kArgUrlPlaceholder)); | 330 tab_list->Set(extracted_index, |
| 331 base::MakeUnique<base::Value>(kArgUrlPlaceholder)); |
| 329 } | 332 } |
| 330 } | 333 } |
| 331 break; | 334 break; |
| 332 } | 335 } |
| 333 | 336 |
| 334 default: | 337 default: |
| 335 NOTREACHED(); | 338 NOTREACHED(); |
| 336 } | 339 } |
| 337 | 340 |
| 338 if (arg_url.is_valid()) { | 341 if (arg_url.is_valid()) { |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 } | 937 } |
| 935 } | 938 } |
| 936 | 939 |
| 937 template <> | 940 template <> |
| 938 void BrowserContextKeyedAPIFactory<ActivityLog>::DeclareFactoryDependencies() { | 941 void BrowserContextKeyedAPIFactory<ActivityLog>::DeclareFactoryDependencies() { |
| 939 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); | 942 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); |
| 940 DependsOn(ExtensionRegistryFactory::GetInstance()); | 943 DependsOn(ExtensionRegistryFactory::GetInstance()); |
| 941 } | 944 } |
| 942 | 945 |
| 943 } // namespace extensions | 946 } // namespace extensions |
| OLD | NEW |