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

Unified Diff: ios/chrome/browser/ui/webui/omaha_ui.cc

Issue 2580333003: Upstream Chrome on iOS source code [10/11]. (Closed)
Patch Set: Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/ui/webui/omaha_ui.h ('k') | ios/chrome/browser/ui/webui/signin_internals_ui_ios.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/ui/webui/omaha_ui.cc
diff --git a/ios/chrome/browser/ui/webui/omaha_ui.cc b/ios/chrome/browser/ui/webui/omaha_ui.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6560ba9e2adc10092c0573467ba8c23947df8c74
--- /dev/null
+++ b/ios/chrome/browser/ui/webui/omaha_ui.cc
@@ -0,0 +1,92 @@
+// Copyright 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 "ios/chrome/browser/ui/webui/omaha_ui.h"
+
+#include "base/memory/weak_ptr.h"
+#include "base/values.h"
+#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
+#include "ios/chrome/browser/chrome_url_constants.h"
+#include "ios/chrome/browser/omaha/omaha_service.h"
+#include "ios/chrome/grit/ios_resources.h"
+#include "ios/web/public/web_ui_ios_data_source.h"
+#include "ios/web/public/webui/web_ui_ios.h"
+#include "ios/web/public/webui/web_ui_ios_message_handler.h"
+
+using web::WebUIIOSMessageHandler;
+
+namespace {
+
+web::WebUIIOSDataSource* CreateOmahaUIHTMLSource() {
+ web::WebUIIOSDataSource* source =
+ web::WebUIIOSDataSource::Create(kChromeUIOmahaHost);
+
+ source->SetJsonPath("strings.js");
+ source->AddResourcePath("omaha.js", IDR_IOS_OMAHA_JS);
+ source->SetDefaultResource(IDR_IOS_OMAHA_HTML);
+ return source;
+}
+
+// OmahaDOMHandler
+
+// The handler for Javascript messages for the chrome://omaha/ page.
+class OmahaDOMHandler : public WebUIIOSMessageHandler {
+ public:
+ OmahaDOMHandler();
+ ~OmahaDOMHandler() override;
+
+ // WebUIIOSMessageHandler implementation.
+ void RegisterMessages() override;
+
+ private:
+ // Asynchronously fetches the debug information. Called from JS.
+ void HandleRequestDebugInformation(const base::ListValue* args);
+
+ // Called when the debug information have been computed.
+ void OnDebugInformationAvailable(base::DictionaryValue* debug_information);
+
+ // WeakPtr factory needed because this object might be deleted before
+ // receiving the callbacks from the OmahaService.
+ base::WeakPtrFactory<OmahaDOMHandler> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(OmahaDOMHandler);
+};
+
+OmahaDOMHandler::OmahaDOMHandler() : weak_ptr_factory_(this) {}
+
+OmahaDOMHandler::~OmahaDOMHandler() {}
+
+void OmahaDOMHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback(
+ "requestOmahaDebugInformation",
+ base::Bind(&OmahaDOMHandler::HandleRequestDebugInformation,
+ base::Unretained(this)));
+}
+
+void OmahaDOMHandler::HandleRequestDebugInformation(
+ const base::ListValue* args) {
+ OmahaService::GetDebugInformation(
+ base::Bind(&OmahaDOMHandler::OnDebugInformationAvailable,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void OmahaDOMHandler::OnDebugInformationAvailable(
+ base::DictionaryValue* debug_information) {
+ web_ui()->CallJavascriptFunction("updateOmahaDebugInformation",
+ *debug_information);
+}
+
+} // namespace
+
+// OmahaUI
+OmahaUI::OmahaUI(web::WebUIIOS* web_ui) : WebUIIOSController(web_ui) {
+ web_ui->AddMessageHandler(new OmahaDOMHandler());
+
+ // Set up the chrome://omaha/ source.
+ ios::ChromeBrowserState* browser_state =
+ ios::ChromeBrowserState::FromWebUIIOS(web_ui);
+ web::WebUIIOSDataSource::Add(browser_state, CreateOmahaUIHTMLSource());
+}
+
+OmahaUI::~OmahaUI() {}
« no previous file with comments | « ios/chrome/browser/ui/webui/omaha_ui.h ('k') | ios/chrome/browser/ui/webui/signin_internals_ui_ios.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698