Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / chrome / renderer / net / net_error_page_controller.cc
blob495c5b10fcb71c60ee04f788bae5b42d50c43252
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/renderer/net/net_error_page_controller.h"
7 #include "base/strings/string_piece.h"
8 #include "content/public/renderer/render_frame.h"
9 #include "gin/handle.h"
10 #include "gin/object_template_builder.h"
11 #include "third_party/WebKit/public/web/WebKit.h"
12 #include "third_party/WebKit/public/web/WebLocalFrame.h"
14 gin::WrapperInfo NetErrorPageController::kWrapperInfo = {
15 gin::kEmbedderNativeGin};
17 NetErrorPageController::Delegate::Delegate() {}
18 NetErrorPageController::Delegate::~Delegate() {}
20 // static
21 void NetErrorPageController::Install(content::RenderFrame* render_frame,
22 base::WeakPtr<Delegate> delegate) {
23 v8::Isolate* isolate = blink::mainThreadIsolate();
24 v8::HandleScope handle_scope(isolate);
25 v8::Local<v8::Context> context =
26 render_frame->GetWebFrame()->mainWorldScriptContext();
27 if (context.IsEmpty())
28 return;
30 v8::Context::Scope context_scope(context);
32 gin::Handle<NetErrorPageController> controller = gin::CreateHandle(
33 isolate, new NetErrorPageController(delegate));
34 if (controller.IsEmpty())
35 return;
37 v8::Local<v8::Object> global = context->Global();
38 global->Set(gin::StringToV8(isolate, "errorPageController"),
39 controller.ToV8());
42 bool NetErrorPageController::ShowSavedCopyButtonClick() {
43 return ButtonClick(error_page::NetErrorHelperCore::SHOW_SAVED_COPY_BUTTON);
46 bool NetErrorPageController::ReloadButtonClick() {
47 return ButtonClick(error_page::NetErrorHelperCore::RELOAD_BUTTON);
50 bool NetErrorPageController::DetailsButtonClick() {
51 return ButtonClick(error_page::NetErrorHelperCore::MORE_BUTTON);
54 bool NetErrorPageController::TrackEasterEgg() {
55 return ButtonClick(error_page::NetErrorHelperCore::EASTER_EGG);
58 bool NetErrorPageController::DiagnoseErrorsButtonClick() {
59 return ButtonClick(error_page::NetErrorHelperCore::DIAGNOSE_ERROR);
62 bool NetErrorPageController::TrackCachedCopyButtonClick() {
63 return ButtonClick(error_page::NetErrorHelperCore::SHOW_CACHED_COPY_BUTTON);
66 bool NetErrorPageController::TrackClick(const gin::Arguments& args) {
67 if (args.PeekNext().IsEmpty() || !args.PeekNext()->IsInt32())
68 return false;
70 if (delegate_)
71 delegate_->TrackClick(args.PeekNext()->Int32Value());
72 return true;
75 bool NetErrorPageController::ButtonClick(
76 error_page::NetErrorHelperCore::Button button) {
77 if (delegate_)
78 delegate_->ButtonPressed(button);
80 return true;
83 NetErrorPageController::NetErrorPageController(base::WeakPtr<Delegate> delegate)
84 : delegate_(delegate) {
87 NetErrorPageController::~NetErrorPageController() {}
89 gin::ObjectTemplateBuilder NetErrorPageController::GetObjectTemplateBuilder(
90 v8::Isolate* isolate) {
91 return gin::Wrappable<NetErrorPageController>::GetObjectTemplateBuilder(
92 isolate)
93 .SetMethod("showSavedCopyButtonClick",
94 &NetErrorPageController::ShowSavedCopyButtonClick)
95 .SetMethod("reloadButtonClick",
96 &NetErrorPageController::ReloadButtonClick)
97 .SetMethod("detailsButtonClick",
98 &NetErrorPageController::DetailsButtonClick)
99 .SetMethod("diagnoseErrorsButtonClick",
100 &NetErrorPageController::DiagnoseErrorsButtonClick)
101 .SetMethod("trackClick",
102 &NetErrorPageController::TrackClick)
103 .SetMethod("trackEasterEgg",
104 &NetErrorPageController::TrackEasterEgg)
105 .SetMethod("trackCachedCopyButtonClick",
106 &NetErrorPageController::TrackCachedCopyButtonClick);