Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: chrome/browser/ui/webui/history_ui.cc

Issue 12769024: History: Fix console errors on Android, and add some iOS ifdefs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ui/webui/history_ui.h" 5 #include "chrome/browser/ui/webui/history_ui.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "grit/generated_resources.h" 50 #include "grit/generated_resources.h"
51 #include "grit/theme_resources.h" 51 #include "grit/theme_resources.h"
52 #include "net/base/escape.h" 52 #include "net/base/escape.h"
53 #include "sync/protocol/history_delete_directive_specifics.pb.h" 53 #include "sync/protocol/history_delete_directive_specifics.pb.h"
54 #include "ui/base/l10n/l10n_util.h" 54 #include "ui/base/l10n/l10n_util.h"
55 #include "ui/base/resource/resource_bundle.h" 55 #include "ui/base/resource/resource_bundle.h"
56 56
57 #if defined(OS_ANDROID) 57 #if defined(OS_ANDROID)
58 #include "chrome/browser/ui/android/tab_model/tab_model.h" 58 #include "chrome/browser/ui/android/tab_model/tab_model.h"
59 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" 59 #include "chrome/browser/ui/android/tab_model/tab_model_list.h"
60 #else 60 #endif
61
62 #if !defined(OS_ANDROID) && !defined(OS_IOS)
61 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h" 63 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h"
62 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h" 64 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h"
63 #endif 65 #endif
64 66
65 static const char kStringsJsFile[] = "strings.js"; 67 static const char kStringsJsFile[] = "strings.js";
66 static const char kHistoryJsFile[] = "history.js"; 68 static const char kHistoryJsFile[] = "history.js";
67 static const char kOtherDevicesJsFile[] = "other_devices.js"; 69 static const char kOtherDevicesJsFile[] = "other_devices.js";
68 70
69 // The amount of time to wait for a response from the WebHistoryService. 71 // The amount of time to wait for a response from the WebHistoryService.
70 static const int kWebHistoryTimeoutSeconds = 3; 72 static const int kWebHistoryTimeoutSeconds = 3;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 source->AddBoolean("groupByDomain", 153 source->AddBoolean("groupByDomain",
152 CommandLine::ForCurrentProcess()->HasSwitch( 154 CommandLine::ForCurrentProcess()->HasSwitch(
153 switches::kHistoryEnableGroupByDomain)); 155 switches::kHistoryEnableGroupByDomain));
154 source->SetJsonPath(kStringsJsFile); 156 source->SetJsonPath(kStringsJsFile);
155 source->AddResourcePath(kHistoryJsFile, IDR_HISTORY_JS); 157 source->AddResourcePath(kHistoryJsFile, IDR_HISTORY_JS);
156 source->AddResourcePath(kOtherDevicesJsFile, IDR_OTHER_DEVICES_JS); 158 source->AddResourcePath(kOtherDevicesJsFile, IDR_OTHER_DEVICES_JS);
157 source->SetDefaultResource(IDR_HISTORY_HTML); 159 source->SetDefaultResource(IDR_HISTORY_HTML);
158 source->SetUseJsonJSFormatV2(); 160 source->SetUseJsonJSFormatV2();
159 source->DisableDenyXFrameOptions(); 161 source->DisableDenyXFrameOptions();
160 162
161 #if !defined(OS_ANDROID) 163 #if defined(OS_ANDROID) || defined(OS_IOS)
164 source->AddBoolean("isManagedProfile", false);
165 #else
162 source->AddBoolean("isManagedProfile", 166 source->AddBoolean("isManagedProfile",
163 ManagedUserServiceFactory::GetForProfile(profile)->ProfileIsManaged()); 167 ManagedUserServiceFactory::GetForProfile(profile)->ProfileIsManaged());
164 #endif 168 #endif
165 169
166 return source; 170 return source;
167 } 171 }
168 172
169 // Returns a localized version of |visit_time| including a relative 173 // Returns a localized version of |visit_time| including a relative
170 // indicator (e.g. today, yesterday). 174 // indicator (e.g. today, yesterday).
171 string16 getRelativeDateLocalized(const base::Time& visit_time) { 175 string16 getRelativeDateLocalized(const base::Time& visit_time) {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 base::Unretained(this))); 375 base::Unretained(this)));
372 web_ui()->RegisterMessageCallback("removeVisits", 376 web_ui()->RegisterMessageCallback("removeVisits",
373 base::Bind(&BrowsingHistoryHandler::HandleRemoveVisits, 377 base::Bind(&BrowsingHistoryHandler::HandleRemoveVisits,
374 base::Unretained(this))); 378 base::Unretained(this)));
375 web_ui()->RegisterMessageCallback("clearBrowsingData", 379 web_ui()->RegisterMessageCallback("clearBrowsingData",
376 base::Bind(&BrowsingHistoryHandler::HandleClearBrowsingData, 380 base::Bind(&BrowsingHistoryHandler::HandleClearBrowsingData,
377 base::Unretained(this))); 381 base::Unretained(this)));
378 web_ui()->RegisterMessageCallback("removeBookmark", 382 web_ui()->RegisterMessageCallback("removeBookmark",
379 base::Bind(&BrowsingHistoryHandler::HandleRemoveBookmark, 383 base::Bind(&BrowsingHistoryHandler::HandleRemoveBookmark,
380 base::Unretained(this))); 384 base::Unretained(this)));
381 #if !defined(OS_ANDROID) 385 #if !defined(OS_ANDROID) && !defined(OS_IOS)
382 web_ui()->RegisterMessageCallback("processManagedUrls", 386 web_ui()->RegisterMessageCallback("processManagedUrls",
383 base::Bind(&BrowsingHistoryHandler::HandleProcessManagedUrls, 387 base::Bind(&BrowsingHistoryHandler::HandleProcessManagedUrls,
384 base::Unretained(this))); 388 base::Unretained(this)));
385 #endif 389 #endif
386 #if defined(ENABLE_MANAGED_USERS) 390 #if defined(ENABLE_MANAGED_USERS)
387 web_ui()->RegisterMessageCallback("setManagedUserElevated", 391 web_ui()->RegisterMessageCallback("setManagedUserElevated",
388 base::Bind(&BrowsingHistoryHandler::HandleSetElevated, 392 base::Bind(&BrowsingHistoryHandler::HandleSetElevated,
389 base::Unretained(this))); 393 base::Unretained(this)));
390 web_ui()->RegisterMessageCallback("getManagedUserElevated", 394 web_ui()->RegisterMessageCallback("getManagedUserElevated",
391 base::Bind(&BrowsingHistoryHandler::HandleManagedUserGetElevated, 395 base::Bind(&BrowsingHistoryHandler::HandleManagedUserGetElevated,
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 &delete_task_tracker_); 586 &delete_task_tracker_);
583 587
584 if (web_history) { 588 if (web_history) {
585 web_history_delete_request_ = web_history->ExpireHistory( 589 web_history_delete_request_ = web_history->ExpireHistory(
586 expire_list, 590 expire_list,
587 base::Bind(&BrowsingHistoryHandler::RemoveWebHistoryComplete, 591 base::Bind(&BrowsingHistoryHandler::RemoveWebHistoryComplete,
588 base::Unretained(this))); 592 base::Unretained(this)));
589 } 593 }
590 } 594 }
591 595
592 #if !defined(OS_ANDROID) 596 #if !defined(OS_ANDROID) && !defined(OS_IOS)
593 void BrowsingHistoryHandler::HandleProcessManagedUrls(const ListValue* args) { 597 void BrowsingHistoryHandler::HandleProcessManagedUrls(const ListValue* args) {
594 bool allow = false; 598 bool allow = false;
595 if (!args->GetBoolean(0, &allow)) { 599 if (!args->GetBoolean(0, &allow)) {
596 LOG(ERROR) << "Unable to extract boolean argument."; 600 LOG(ERROR) << "Unable to extract boolean argument.";
597 web_ui()->CallJavascriptFunction("processingManagedFailed"); 601 web_ui()->CallJavascriptFunction("processingManagedFailed");
598 return; 602 return;
599 } 603 }
600 604
601 // Check if the managed user is authenticated. 605 // Check if the managed user is authenticated.
602 ManagedUserService* service = ManagedUserServiceFactory::GetForProfile( 606 ManagedUserService* service = ManagedUserServiceFactory::GetForProfile(
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 entry->SetInteger("manualBehavior", manual_behavior); 700 entry->SetInteger("manualBehavior", manual_behavior);
697 entry->SetInteger("inContentPack", !sites.empty()); 701 entry->SetInteger("inContentPack", !sites.empty());
698 result_urls->SetWithoutPathExpansion(it->spec(), entry.release()); 702 result_urls->SetWithoutPathExpansion(it->spec(), entry.release());
699 } 703 }
700 results.Append(result_urls.release()); 704 results.Append(result_urls.release());
701 705
702 // Notify the Javascript side that the changes have been commited and that it 706 // Notify the Javascript side that the changes have been commited and that it
703 // should update the page. 707 // should update the page.
704 web_ui()->CallJavascriptFunction("updateEntries", results); 708 web_ui()->CallJavascriptFunction("updateEntries", results);
705 } 709 }
706 #endif // defined(OS_ANDROID) 710 #endif // !defined(OS_ANDROID) && !defined(OS_IOS)
707 711
708 void BrowsingHistoryHandler::HandleClearBrowsingData(const ListValue* args) { 712 void BrowsingHistoryHandler::HandleClearBrowsingData(const ListValue* args) {
709 #if defined(OS_ANDROID) 713 #if defined(OS_ANDROID)
710 Profile* profile = Profile::FromWebUI(web_ui()); 714 Profile* profile = Profile::FromWebUI(web_ui());
711 const TabModel* tab_model = 715 const TabModel* tab_model =
712 TabModelList::GetTabModelWithProfile(profile); 716 TabModelList::GetTabModelWithProfile(profile);
713 if (tab_model) 717 if (tab_model)
714 tab_model->OpenClearBrowsingData(); 718 tab_model->OpenClearBrowsingData();
715 #else 719 #else
716 // TODO(beng): This is an improper direct dependency on Browser. Route this 720 // TODO(beng): This is an improper direct dependency on Browser. Route this
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 1088
1085 //////////////////////////////////////////////////////////////////////////////// 1089 ////////////////////////////////////////////////////////////////////////////////
1086 // 1090 //
1087 // HistoryUI 1091 // HistoryUI
1088 // 1092 //
1089 //////////////////////////////////////////////////////////////////////////////// 1093 ////////////////////////////////////////////////////////////////////////////////
1090 1094
1091 HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { 1095 HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) {
1092 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); 1096 web_ui->AddMessageHandler(new BrowsingHistoryHandler());
1093 1097
1094 // Android deals with foreign sessions differently. 1098 // On mobile we deal with foreign sessions differently.
1095 #if !defined(OS_ANDROID) 1099 #if !defined(OS_ANDROID) && !defined(OS_IOS)
1096 if (chrome::search::IsInstantExtendedAPIEnabled()) { 1100 if (chrome::search::IsInstantExtendedAPIEnabled()) {
1097 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); 1101 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler());
1098 web_ui->AddMessageHandler(new NTPLoginHandler()); 1102 web_ui->AddMessageHandler(new NTPLoginHandler());
1099 } 1103 }
1100 #endif // !defined(OS_ANDROID) 1104 #endif
1101 1105
1102 // Set up the chrome://history-frame/ source. 1106 // Set up the chrome://history-frame/ source.
1103 Profile* profile = Profile::FromWebUI(web_ui); 1107 Profile* profile = Profile::FromWebUI(web_ui);
1104 content::WebUIDataSource::Add(profile, CreateHistoryUIHTMLSource(profile)); 1108 content::WebUIDataSource::Add(profile, CreateHistoryUIHTMLSource(profile));
1105 } 1109 }
1106 1110
1107 // static 1111 // static
1108 const GURL HistoryUI::GetHistoryURLWithSearchText(const string16& text) { 1112 const GURL HistoryUI::GetHistoryURLWithSearchText(const string16& text) {
1109 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + 1113 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" +
1110 net::EscapeQueryParamValue(UTF16ToUTF8(text), true)); 1114 net::EscapeQueryParamValue(UTF16ToUTF8(text), true));
1111 } 1115 }
1112 1116
1113 // static 1117 // static
1114 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( 1118 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes(
1115 ui::ScaleFactor scale_factor) { 1119 ui::ScaleFactor scale_factor) {
1116 return ResourceBundle::GetSharedInstance(). 1120 return ResourceBundle::GetSharedInstance().
1117 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); 1121 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor);
1118 } 1122 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698