Return Windows error code when create-process fails.
[chromium-blink-merge.git] / chrome / renderer / net / net_error_page_controller.cc
blob3499a984539151e961172efe37439f7a91d15516
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(bool is_default_label) {
63 return is_default_label ?
64 ButtonClick(error_page::NetErrorHelperCore::SHOW_CACHED_PAGE_BUTTON) :
65 ButtonClick(error_page::NetErrorHelperCore::SHOW_CACHED_COPY_BUTTON);
68 bool NetErrorPageController::TrackClick(const gin::Arguments& args) {
69 if (args.PeekNext().IsEmpty() || !args.PeekNext()->IsInt32())
70 return false;
72 if (delegate_)
73 delegate_->TrackClick(args.PeekNext()->Int32Value());
74 return true;
77 bool NetErrorPageController::ButtonClick(
78 error_page::NetErrorHelperCore::Button button) {
79 if (delegate_)
80 delegate_->ButtonPressed(button);
82 return true;
85 NetErrorPageController::NetErrorPageController(base::WeakPtr<Delegate> delegate)
86 : delegate_(delegate) {
89 NetErrorPageController::~NetErrorPageController() {}
91 gin::ObjectTemplateBuilder NetErrorPageController::GetObjectTemplateBuilder(
92 v8::Isolate* isolate) {
93 return gin::Wrappable<NetErrorPageController>::GetObjectTemplateBuilder(
94 isolate)
95 .SetMethod("showSavedCopyButtonClick",
96 &NetErrorPageController::ShowSavedCopyButtonClick)
97 .SetMethod("reloadButtonClick",
98 &NetErrorPageController::ReloadButtonClick)
99 .SetMethod("detailsButtonClick",
100 &NetErrorPageController::DetailsButtonClick)
101 .SetMethod("diagnoseErrorsButtonClick",
102 &NetErrorPageController::DiagnoseErrorsButtonClick)
103 .SetMethod("trackClick",
104 &NetErrorPageController::TrackClick)
105 .SetMethod("trackEasterEgg",
106 &NetErrorPageController::TrackEasterEgg)
107 .SetMethod("trackCachedCopyButtonClick",
108 &NetErrorPageController::TrackCachedCopyButtonClick);