| 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 <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 | 239 |
| 240 switch (api_info->arg_url_transform) { | 240 switch (api_info->arg_url_transform) { |
| 241 case NONE: { | 241 case NONE: { |
| 242 // No translation needed; just extract the URL directly from a raw string | 242 // No translation needed; just extract the URL directly from a raw string |
| 243 // or from a dictionary. Succeeds if we can find a string in the | 243 // or from a dictionary. Succeeds if we can find a string in the |
| 244 // argument list and that the string resolves to a valid URL. | 244 // argument list and that the string resolves to a valid URL. |
| 245 std::string url_string; | 245 std::string url_string; |
| 246 if (action->args()->GetString(url_index, &url_string) && | 246 if (action->args()->GetString(url_index, &url_string) && |
| 247 ResolveUrl(action->page_url(), url_string, &arg_url)) { | 247 ResolveUrl(action->page_url(), url_string, &arg_url)) { |
| 248 action->mutable_args()->Set(url_index, | 248 action->mutable_args()->Set(url_index, |
| 249 new StringValue(kArgUrlPlaceholder)); | 249 new base::StringValue(kArgUrlPlaceholder)); |
| 250 } | 250 } |
| 251 break; | 251 break; |
| 252 } | 252 } |
| 253 | 253 |
| 254 case DICT_LOOKUP: { | 254 case DICT_LOOKUP: { |
| 255 CHECK(api_info->arg_url_dict_path); | 255 CHECK(api_info->arg_url_dict_path); |
| 256 // Look up the URL from a dictionary at the specified location. Succeeds | 256 // Look up the URL from a dictionary at the specified location. Succeeds |
| 257 // if we can find a dictionary in the argument list, the dictionary | 257 // if we can find a dictionary in the argument list, the dictionary |
| 258 // contains the specified key, and the corresponding value resolves to a | 258 // contains the specified key, and the corresponding value resolves to a |
| 259 // valid URL. | 259 // valid URL. |
| 260 DictionaryValue* dict = NULL; | 260 base::DictionaryValue* dict = NULL; |
| 261 std::string url_string; | 261 std::string url_string; |
| 262 if (action->mutable_args()->GetDictionary(url_index, &dict) && | 262 if (action->mutable_args()->GetDictionary(url_index, &dict) && |
| 263 dict->GetString(api_info->arg_url_dict_path, &url_string) && | 263 dict->GetString(api_info->arg_url_dict_path, &url_string) && |
| 264 ResolveUrl(action->page_url(), url_string, &arg_url)) { | 264 ResolveUrl(action->page_url(), url_string, &arg_url)) { |
| 265 dict->SetString(api_info->arg_url_dict_path, kArgUrlPlaceholder); | 265 dict->SetString(api_info->arg_url_dict_path, kArgUrlPlaceholder); |
| 266 } | 266 } |
| 267 break; | 267 break; |
| 268 } | 268 } |
| 269 | 269 |
| 270 case LOOKUP_TAB_ID: { | 270 case LOOKUP_TAB_ID: { |
| 271 // Translation of tab IDs to URLs has been requested. There are two | 271 // Translation of tab IDs to URLs has been requested. There are two |
| 272 // cases to consider: either a single integer or a list of integers (when | 272 // cases to consider: either a single integer or a list of integers (when |
| 273 // multiple tabs are manipulated). | 273 // multiple tabs are manipulated). |
| 274 int tab_id; | 274 int tab_id; |
| 275 base::ListValue* tab_list = NULL; | 275 base::ListValue* tab_list = NULL; |
| 276 if (action->args()->GetInteger(url_index, &tab_id)) { | 276 if (action->args()->GetInteger(url_index, &tab_id)) { |
| 277 // Single tab ID to translate. | 277 // Single tab ID to translate. |
| 278 GetUrlForTabId(tab_id, profile, &arg_url, &arg_incognito); | 278 GetUrlForTabId(tab_id, profile, &arg_url, &arg_incognito); |
| 279 if (arg_url.is_valid()) { | 279 if (arg_url.is_valid()) { |
| 280 action->mutable_args()->Set(url_index, | 280 action->mutable_args()->Set( |
| 281 new StringValue(kArgUrlPlaceholder)); | 281 url_index, new base::StringValue(kArgUrlPlaceholder)); |
| 282 } | 282 } |
| 283 } else if (action->mutable_args()->GetList(url_index, &tab_list)) { | 283 } else if (action->mutable_args()->GetList(url_index, &tab_list)) { |
| 284 // A list of possible IDs to translate. Work through in reverse order | 284 // A list of possible IDs to translate. Work through in reverse order |
| 285 // so the last one translated is left in arg_url. | 285 // so the last one translated is left in arg_url. |
| 286 int extracted_index = -1; // Which list item is copied to arg_url? | 286 int extracted_index = -1; // Which list item is copied to arg_url? |
| 287 for (int i = tab_list->GetSize() - 1; i >= 0; --i) { | 287 for (int i = tab_list->GetSize() - 1; i >= 0; --i) { |
| 288 if (tab_list->GetInteger(i, &tab_id) && | 288 if (tab_list->GetInteger(i, &tab_id) && |
| 289 GetUrlForTabId(tab_id, profile, &arg_url, &arg_incognito)) { | 289 GetUrlForTabId(tab_id, profile, &arg_url, &arg_incognito)) { |
| 290 if (!arg_incognito) | 290 if (!arg_incognito) |
| 291 tab_list->Set(i, new base::StringValue(arg_url.spec())); | 291 tab_list->Set(i, new base::StringValue(arg_url.spec())); |
| 292 extracted_index = i; | 292 extracted_index = i; |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 if (extracted_index >= 0) | 295 if (extracted_index >= 0) { |
| 296 tab_list->Set(extracted_index, new StringValue(kArgUrlPlaceholder)); | 296 tab_list->Set( |
| 297 extracted_index, new base::StringValue(kArgUrlPlaceholder)); |
| 298 } |
| 297 } | 299 } |
| 298 break; | 300 break; |
| 299 } | 301 } |
| 300 | 302 |
| 301 default: | 303 default: |
| 302 NOTREACHED(); | 304 NOTREACHED(); |
| 303 } | 305 } |
| 304 | 306 |
| 305 if (arg_url.is_valid()) { | 307 if (arg_url.is_valid()) { |
| 306 action->set_arg_incognito(arg_incognito); | 308 action->set_arg_incognito(arg_incognito); |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 return; | 546 return; |
| 545 | 547 |
| 546 // Perform some preprocessing of the Action data: convert tab IDs to URLs and | 548 // Perform some preprocessing of the Action data: convert tab IDs to URLs and |
| 547 // mask out incognito URLs if appropriate. | 549 // mask out incognito URLs if appropriate. |
| 548 ExtractUrls(action, profile_); | 550 ExtractUrls(action, profile_); |
| 549 | 551 |
| 550 // Mark DOM XHR requests as such, for easier processing later. | 552 // Mark DOM XHR requests as such, for easier processing later. |
| 551 if (action->action_type() == Action::ACTION_DOM_ACCESS && | 553 if (action->action_type() == Action::ACTION_DOM_ACCESS && |
| 552 StartsWithASCII(action->api_name(), kDomXhrPrefix, true) && | 554 StartsWithASCII(action->api_name(), kDomXhrPrefix, true) && |
| 553 action->other()) { | 555 action->other()) { |
| 554 DictionaryValue* other = action->mutable_other(); | 556 base::DictionaryValue* other = action->mutable_other(); |
| 555 int dom_verb = -1; | 557 int dom_verb = -1; |
| 556 if (other->GetInteger(constants::kActionDomVerb, &dom_verb) && | 558 if (other->GetInteger(constants::kActionDomVerb, &dom_verb) && |
| 557 dom_verb == DomActionType::METHOD) { | 559 dom_verb == DomActionType::METHOD) { |
| 558 other->SetInteger(constants::kActionDomVerb, DomActionType::XHR); | 560 other->SetInteger(constants::kActionDomVerb, DomActionType::XHR); |
| 559 } | 561 } |
| 560 } | 562 } |
| 561 | 563 |
| 562 if (uma_policy_) | 564 if (uma_policy_) |
| 563 uma_policy_->ProcessAction(action); | 565 uma_policy_->ProcessAction(action); |
| 564 if (IsDatabaseEnabled() && database_policy_) | 566 if (IsDatabaseEnabled() && database_policy_) |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 RemoveURLs(urls); | 671 RemoveURLs(urls); |
| 670 } | 672 } |
| 671 | 673 |
| 672 void ActivityLog::DeleteDatabase() { | 674 void ActivityLog::DeleteDatabase() { |
| 673 if (!database_policy_) | 675 if (!database_policy_) |
| 674 return; | 676 return; |
| 675 database_policy_->DeleteDatabase(); | 677 database_policy_->DeleteDatabase(); |
| 676 } | 678 } |
| 677 | 679 |
| 678 } // namespace extensions | 680 } // namespace extensions |
| OLD | NEW |