diff options
Diffstat (limited to 'chrome/browser')
14 files changed, 313 insertions, 4 deletions
diff --git a/chrome/browser/autocomplete/network_action_predictor.cc b/chrome/browser/autocomplete/network_action_predictor.cc index e310d73..fff5bb9 100644 --- a/chrome/browser/autocomplete/network_action_predictor.cc +++ b/chrome/browser/autocomplete/network_action_predictor.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -411,6 +411,11 @@ double NetworkActionPredictor::CalculateConfidence( return 0.0; *is_in_db = true; + return CalculateConfidenceForDbEntry(iter); +} + +double NetworkActionPredictor::CalculateConfidenceForDbEntry( + DBCacheMap::const_iterator iter) const { const DBCacheValue& value = iter->second; if (value.number_of_hits < kMinimumNumberOfHits) return 0.0; diff --git a/chrome/browser/autocomplete/network_action_predictor.h b/chrome/browser/autocomplete/network_action_predictor.h index 16562e1..0f3068a 100644 --- a/chrome/browser/autocomplete/network_action_predictor.h +++ b/chrome/browser/autocomplete/network_action_predictor.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -76,6 +76,7 @@ class NetworkActionPredictor private: friend class NetworkActionPredictorTest; + friend class NetworkActionPredictorDOMHandler; struct TransitionalMatch { TransitionalMatch(); @@ -153,6 +154,9 @@ class NetworkActionPredictor const AutocompleteMatch& match, bool* is_in_db) const; + // Calculates the confidence for an entry in the DBCacheMap. + double CalculateConfidenceForDbEntry(DBCacheMap::const_iterator iter) const; + // Adds a row to the database and caches. void AddRow(const DBCacheKey& key, const NetworkActionPredictorDatabase::Row& row); diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc index 8b72f1d..3e93cb7 100644 --- a/chrome/browser/browser_about_handler.cc +++ b/chrome/browser/browser_about_handler.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -44,6 +44,7 @@ const char* const kChromePaths[] = { chrome::kChromeUIMediaInternalsHost, chrome::kChromeUIMemoryHost, chrome::kChromeUINetInternalsHost, + chrome::kChromeUINetworkActionPredictorHost, chrome::kChromeUINetworkViewCacheHost, chrome::kChromeUINewTabHost, chrome::kChromeUIPluginsHost, diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd index 4ade6d7..7aafb2c 100644 --- a/chrome/browser/browser_resources.grd +++ b/chrome/browser/browser_resources.grd @@ -77,6 +77,8 @@ <include name="IDR_KEYBOARD_MANIFEST" file="resources\keyboard\manifest.json" type="BINDATA" /> <include name="IDR_MEDIA_INTERNALS_HTML" file="resources\media_internals.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" /> <include name="IDR_MEDIA_INTERNALS_JS" file="resources\media_internals\media_internals.js" flattenhtml="true" type="BINDATA" /> + <include name="IDR_NETWORK_ACTION_PREDICTOR_HTML" file="resources\network_action_predictor\network_action_predictor.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" /> + <include name="IDR_NETWORK_ACTION_PREDICTOR_JS" file="resources\network_action_predictor\network_action_predictor.js" type="BINDATA" /> <include name="IDR_NEW_INCOGNITO_TAB_THEME_CSS" file="resources\new_incognito_tab_theme.css" flattenhtml="true" type="BINDATA" /> <include name="IDR_NEW_TAB_4_HTML" file="resources\ntp4\new_tab.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_NEW_TAB_4_THEME_CSS" file="resources\ntp4\new_tab_theme.css" flattenhtml="true" type="BINDATA" /> diff --git a/chrome/browser/resources/network_action_predictor/OWNERS b/chrome/browser/resources/network_action_predictor/OWNERS new file mode 100644 index 0000000..95b3792 --- /dev/null +++ b/chrome/browser/resources/network_action_predictor/OWNERS @@ -0,0 +1 @@ +dominich@chromium.org diff --git a/chrome/browser/resources/network_action_predictor/network_action_predictor.css b/chrome/browser/resources/network_action_predictor/network_action_predictor.css new file mode 100644 index 0000000..73b2f57 --- /dev/null +++ b/chrome/browser/resources/network_action_predictor/network_action_predictor.css @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2012 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +body { + margin: 20px; +} + +h1 { + -webkit-padding-start: 75px; + font-size: 156%; + font-weight: bold; + margin: 0; + padding-bottom: 20px; + padding-top: 20px; +} + +html[dir=rtl] h1 { + background-position: right; +} + +#countBanner { + background-color: rgb(235, 239, 250); + border: 1px solid rgb(187, 187, 187); + border-radius: 2px; + font-size: 100%; + padding: 4px; +} + +#databaseTable { + background-color: white; +} + +#databaseTable thead tr { + background-color: rgb(235, 250, 239); +} + +#databaseTable th { + background-color: white; + border-color: gray; + border-style: solid; + border-width: 1px; + padding: 3px; + white-space: nowrap; +} + +#databaseTable td { + background-color: white; + border-color: lightgray; + border-style: solid; + border-width: 1px; + padding: 3px; +} + +#databaseTable tbody > td:first-child { + white-space: nowrap; +} + +#disabledMode h2 { + color: rgb(141, 51, 42); + font-size: 125%; +} + diff --git a/chrome/browser/resources/network_action_predictor/network_action_predictor.html b/chrome/browser/resources/network_action_predictor/network_action_predictor.html new file mode 100644 index 0000000..abc230c --- /dev/null +++ b/chrome/browser/resources/network_action_predictor/network_action_predictor.html @@ -0,0 +1,35 @@ +<!DOCTYPE HTML> +<html> +<head> + <meta charset="utf-8"> + <title>Network Action Predictor</title> + <link rel="stylesheet" href="network_action_predictor.css"> + <script src="chrome://resources/js/util.js"></script> + <script src="chrome://network-action-predictor/network_action_predictor.js"> + </script> +</head> +<body> + <header><h1>Network Action Predictor</h1></header> + <div id="enabledMode" hidden> + <h2 id="countBanner"></h2> + <!-- TODO(dominich): Filtering checkbox. Sorting. --> + <table id="databaseTable"> + <thead> + <tr> + <th>User Text</th> + <th>URL</th> + <th>Hit Count</th> + <th>Miss Count</th> + <th>Confidence</th> + </tr> + </thead> + <tbody id="databaseTableBody"> + </tbody> + </table> + </div> + <div id="disabledMode" hidden> + <p>Network Action Predictor is disabled.</p> + </div> + <script src="chrome://resources/js/jstemplate_compiled.js"></script> +</body> +</html> diff --git a/chrome/browser/resources/network_action_predictor/network_action_predictor.js b/chrome/browser/resources/network_action_predictor/network_action_predictor.js new file mode 100644 index 0000000..06f30a5 --- /dev/null +++ b/chrome/browser/resources/network_action_predictor/network_action_predictor.js @@ -0,0 +1,49 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/** + * Requests the database from the backend. + */ +function requestNetworkActionPredictorDb() { + console.debug('Requesting NAP DB'); + chrome.send('requestNetworkActionPredictorDb', []) +} + +/** + * Callback from backend with the database contents. Builds the UI. + * @param {boolean} enabled Whether or not NetworkActionPredictor is enabled. + * @param {array} database The database as a flattened list. + */ +function updateDatabaseTable(enabled, database) { + console.debug('Updating Table NAP DB'); + $('countBanner').textContent = 'Entries: ' + database.length; + + $('enabledMode').hidden = !enabled; + $('disabledMode').hidden = enabled; + + if (!enabled) + return; + + var databaseSection = $('databaseTableBody'); + + // Clear any previous list. + databaseSection.textContent = ''; + + for (var i = 0; i < database.length; ++i) { + var entry = database[i]; + var row = document.createElement('tr'); + + row.appendChild(document.createElement('td')).textContent = entry.user_text; + row.appendChild(document.createElement('td')).textContent = entry.url; + row.appendChild(document.createElement('td')).textContent = entry.hit_count; + row.appendChild(document.createElement('td')).textContent = + entry.miss_count; + row.appendChild(document.createElement('td')).textContent = + entry.confidence; + + databaseSection.appendChild(row); + } +} + +document.addEventListener('DOMContentLoaded', requestNetworkActionPredictorDb); diff --git a/chrome/browser/ui/webui/chrome_web_ui_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_factory.cc index ad737b6..7f6bc35 100644 --- a/chrome/browser/ui/webui/chrome_web_ui_factory.cc +++ b/chrome/browser/ui/webui/chrome_web_ui_factory.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -31,6 +31,7 @@ #include "chrome/browser/ui/webui/input_window_dialog_ui.h" #include "chrome/browser/ui/webui/media/media_internals_ui.h" #include "chrome/browser/ui/webui/net_internals_ui.h" +#include "chrome/browser/ui/webui/network_action_predictor/network_action_predictor_ui.h" #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" #include "chrome/browser/ui/webui/options/options_ui.h" #include "chrome/browser/ui/webui/options2/options_ui2.h" @@ -206,6 +207,8 @@ WebUIFactoryFunction GetWebUIFactoryFunction(TabContents* tab_contents, return &NewWebUI<MediaInternalsUI>; if (url.host() == chrome::kChromeUINetInternalsHost) return &NewWebUI<NetInternalsUI>; + if (url.host() == chrome::kChromeUINetworkActionPredictorHost) + return &NewWebUI<NetworkActionPredictorUI>; #if defined(ENABLE_CONFIGURATION_POLICY) if (url.host() == chrome::kChromeUIPolicyHost) return &NewWebUI<PolicyUI>; diff --git a/chrome/browser/ui/webui/network_action_predictor/OWNERS b/chrome/browser/ui/webui/network_action_predictor/OWNERS new file mode 100644 index 0000000..95b3792 --- /dev/null +++ b/chrome/browser/ui/webui/network_action_predictor/OWNERS @@ -0,0 +1 @@ +dominich@chromium.org diff --git a/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_dom_handler.cc b/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_dom_handler.cc new file mode 100644 index 0000000..b9545d0 --- /dev/null +++ b/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_dom_handler.cc @@ -0,0 +1,52 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/webui/network_action_predictor/network_action_predictor_dom_handler.h" + +#include "base/bind.h" +#include "base/values.h" +#include "chrome/browser/autocomplete/network_action_predictor.h" +#include "chrome/browser/autocomplete/network_action_predictor_factory.h" +#include "chrome/browser/profiles/profile.h" +#include "content/browser/webui/web_ui.h" + +NetworkActionPredictorDOMHandler::NetworkActionPredictorDOMHandler( + Profile* profile) { + network_action_predictor_ = + NetworkActionPredictorFactory::GetForProfile(profile); +} + +NetworkActionPredictorDOMHandler::~NetworkActionPredictorDOMHandler() { } + +void NetworkActionPredictorDOMHandler::RegisterMessages() { + web_ui()->RegisterMessageCallback("requestNetworkActionPredictorDb", + base::Bind( + &NetworkActionPredictorDOMHandler::RequestNetworkActionPredictorDb, + base::Unretained(this))); +} + +void NetworkActionPredictorDOMHandler::RequestNetworkActionPredictorDb( + const base::ListValue* args) { + bool enabled = (network_action_predictor_ != NULL); + base::ListValue list; + + if (enabled) { + for (NetworkActionPredictor::DBCacheMap::const_iterator it = + network_action_predictor_->db_cache_.begin(); + it != network_action_predictor_->db_cache_.end(); + ++it) { + base::DictionaryValue* entry = new base::DictionaryValue(); + entry->SetString("user_text", it->first.user_text); + entry->SetString("url", it->first.url.spec()); + entry->SetInteger("hit_count", it->second.number_of_hits); + entry->SetInteger("miss_count", it->second.number_of_misses); + entry->SetDouble("confidence", + network_action_predictor_->CalculateConfidenceForDbEntry(it)); + list.Append(entry); + } + } + + base::FundamentalValue enabled_value(enabled); + web_ui()->CallJavascriptFunction("updateDatabaseTable", enabled_value, list); +} diff --git a/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_dom_handler.h b/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_dom_handler.h new file mode 100644 index 0000000..2c9fc2a --- /dev/null +++ b/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_dom_handler.h @@ -0,0 +1,38 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_WEBUI_NETWORK_ACTION_PREDICTOR_NETWORK_ACTION_PREDICTOR_DOM_HANDLER_H_ +#define CHROME_BROWSER_UI_WEBUI_NETWORK_ACTION_PREDICTOR_NETWORK_ACTION_PREDICTOR_DOM_HANDLER_H_ +#pragma once + +#include "base/compiler_specific.h" +#include "content/public/browser/web_ui_message_handler.h" + +namespace base { +class ListValue; +} + +class NetworkActionPredictor; +class Profile; + +// The handler for Javascript messages for about:network-action-predictor. +class NetworkActionPredictorDOMHandler : public content::WebUIMessageHandler { + public: + explicit NetworkActionPredictorDOMHandler(Profile* profile); + virtual ~NetworkActionPredictorDOMHandler(); + + // WebUIMessageHandler implementation. + virtual void RegisterMessages() OVERRIDE; + + private: + // Synchronously fetches the database from NetworkActionPredictor and calls + // into JS with the resulting DictionaryValue. + void RequestNetworkActionPredictorDb(const base::ListValue* args); + + NetworkActionPredictor* network_action_predictor_; + + DISALLOW_COPY_AND_ASSIGN(NetworkActionPredictorDOMHandler); +}; + +#endif // CHROME_BROWSER_UI_WEBUI_NETWORK_ACTION_PREDICTOR_NETWORK_ACTION_PREDICTOR_DOM_HANDLER_H_ diff --git a/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_ui.cc b/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_ui.cc new file mode 100644 index 0000000..2c6204a --- /dev/null +++ b/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_ui.cc @@ -0,0 +1,34 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/webui/network_action_predictor/network_action_predictor_ui.h" + +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" +#include "chrome/browser/ui/webui/network_action_predictor/network_action_predictor_dom_handler.h" +#include "chrome/common/url_constants.h" +#include "content/public/browser/web_contents.h" +#include "grit/browser_resources.h" + +namespace { + +ChromeWebUIDataSource* CreateNetworkActionPredictorUIHTMLSource() { + ChromeWebUIDataSource* source = + new ChromeWebUIDataSource(chrome::kChromeUINetworkActionPredictorHost); + source->add_resource_path("network_action_predictor.js", + IDR_NETWORK_ACTION_PREDICTOR_JS); + source->set_default_resource(IDR_NETWORK_ACTION_PREDICTOR_HTML); + return source; +} + +} // namespace + +NetworkActionPredictorUI::NetworkActionPredictorUI( + content::WebContents* contents) + : ChromeWebUI(contents) { + Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); + AddMessageHandler(new NetworkActionPredictorDOMHandler(profile)); + profile->GetChromeURLDataManager()->AddDataSource( + CreateNetworkActionPredictorUIHTMLSource()); +} diff --git a/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_ui.h b/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_ui.h new file mode 100644 index 0000000..dc4f1c8 --- /dev/null +++ b/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_ui.h @@ -0,0 +1,19 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_WEBUI_NETWORK_ACTION_PREDICTOR_NETWORK_ACTION_PREDICTOR_UI_H_ +#define CHROME_BROWSER_UI_WEBUI_NETWORK_ACTION_PREDICTOR_NETWORK_ACTION_PREDICTOR_UI_H_ +#pragma once + +#include "chrome/browser/ui/webui/chrome_web_ui.h" + +class NetworkActionPredictorUI : public ChromeWebUI { + public: + explicit NetworkActionPredictorUI(content::WebContents* contents); + + private: + DISALLOW_COPY_AND_ASSIGN(NetworkActionPredictorUI); +}; + +#endif // CHROME_BROWSER_UI_WEBUI_NETWORK_ACTION_PREDICTOR_NETWORK_ACTION_PREDICTOR_UI_H_ |