Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / chrome / renderer / net / net_error_page_controller.cc
blobb44bf03010b18bbc9b319ab823bdbce878233149
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 "chrome/renderer/net/net_error_helper.h"
9 #include "content/public/renderer/render_frame.h"
10 #include "gin/handle.h"
11 #include "gin/object_template_builder.h"
12 #include "third_party/WebKit/public/web/WebKit.h"
13 #include "third_party/WebKit/public/web/WebLocalFrame.h"
15 gin::WrapperInfo NetErrorPageController::kWrapperInfo = {
16 gin::kEmbedderNativeGin};
18 // static
19 void NetErrorPageController::Install(content::RenderFrame* render_frame) {
20 v8::Isolate* isolate = blink::mainThreadIsolate();
21 v8::HandleScope handle_scope(isolate);
22 v8::Handle<v8::Context> context =
23 render_frame->GetWebFrame()->mainWorldScriptContext();
24 if (context.IsEmpty())
25 return;
27 v8::Context::Scope context_scope(context);
29 gin::Handle<NetErrorPageController> controller = gin::CreateHandle(
30 isolate, new NetErrorPageController(render_frame));
31 if (controller.IsEmpty())
32 return;
34 v8::Handle<v8::Object> global = context->Global();
35 global->Set(gin::StringToV8(isolate, "errorPageController"),
36 controller.ToV8());
39 bool NetErrorPageController::ShowSavedCopyButtonClick() {
40 if (!render_frame())
41 return false;
43 NetErrorHelper* net_error_helper =
44 content::RenderFrameObserverTracker<NetErrorHelper>::Get(render_frame());
45 DCHECK(net_error_helper);
46 net_error_helper->ShowSavedCopyButtonPressed();
48 return true;
51 bool NetErrorPageController::ReloadButtonClick() {
52 if (!render_frame())
53 return false;
55 NetErrorHelper* net_error_helper =
56 content::RenderFrameObserverTracker<NetErrorHelper>::Get(render_frame());
57 DCHECK(net_error_helper);
58 net_error_helper->ReloadButtonPressed();
60 return true;
63 bool NetErrorPageController::DetailsButtonClick() {
64 if (!render_frame())
65 return false;
67 NetErrorHelper* net_error_helper =
68 content::RenderFrameObserverTracker<NetErrorHelper>::Get(render_frame());
69 DCHECK(net_error_helper);
70 net_error_helper->MoreButtonPressed();
72 return true;
75 bool NetErrorPageController::TrackClick(const gin::Arguments& args) {
76 if (!render_frame())
77 return false;
79 if (!args.PeekNext()->IsInt32())
80 return false;
82 NetErrorHelper* net_error_helper =
83 content::RenderFrameObserverTracker<NetErrorHelper>::Get(render_frame());
84 DCHECK(net_error_helper);
85 net_error_helper->TrackClick(args.PeekNext()->Int32Value());
86 return true;
89 void NetErrorPageController::TrackEasterEgg() {
90 if (!render_frame())
91 return;
93 NetErrorHelper* net_error_helper =
94 content::RenderFrameObserverTracker<NetErrorHelper>::Get(render_frame());
95 DCHECK(net_error_helper);
96 net_error_helper->TrackActivatedEasterEgg();
99 NetErrorPageController::NetErrorPageController(
100 content::RenderFrame* render_frame) : RenderFrameObserver(render_frame) {}
102 NetErrorPageController::~NetErrorPageController() {}
104 gin::ObjectTemplateBuilder NetErrorPageController::GetObjectTemplateBuilder(
105 v8::Isolate* isolate) {
106 return gin::Wrappable<NetErrorPageController>::GetObjectTemplateBuilder(
107 isolate)
108 .SetMethod("showSavedCopyButtonClick",
109 &NetErrorPageController::ShowSavedCopyButtonClick)
110 .SetMethod("reloadButtonClick",
111 &NetErrorPageController::ReloadButtonClick)
112 .SetMethod("detailsButtonClick",
113 &NetErrorPageController::DetailsButtonClick)
114 .SetMethod("trackClick",
115 &NetErrorPageController::TrackClick)
116 .SetMethod("trackEasterEgg",
117 &NetErrorPageController::TrackEasterEgg);
120 void NetErrorPageController::OnDestruct() {}