OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_REMOTING_SETUP_FLOW_H_ |
| 6 #define CHROME_BROWSER_REMOTING_SETUP_FLOW_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/scoped_ptr.h" |
| 10 #include "chrome/browser/dom_ui/html_dialog_ui.h" |
| 11 |
| 12 class ListValue; |
| 13 |
| 14 namespace remoting { |
| 15 |
| 16 class SetupFlow; |
| 17 |
| 18 // SetupFlowStep represents a single step for SetupFlow, e.g. login or |
| 19 // host registration. When a step is finished, GetNextStep() is called |
| 20 // to get the step that must follow. |
| 21 class SetupFlowStep { |
| 22 public: |
| 23 typedef Callback0::Type DoneCallback; |
| 24 |
| 25 SetupFlowStep(); |
| 26 virtual ~SetupFlowStep(); |
| 27 |
| 28 // Start the step. Ownership of |done_callback| is given to the |
| 29 // function. |done_callback| is called when the step is finished, |
| 30 // The callback must be called on the same thread as Start(). |
| 31 virtual void Start(SetupFlow* flow, DoneCallback* done_callback) = 0; |
| 32 |
| 33 // Called to handle |message| received from UI. |
| 34 virtual void HandleMessage(const std::string& message, |
| 35 const ListValue* args) = 0; |
| 36 |
| 37 // Called if user closes the dialog. |
| 38 virtual void Cancel() = 0; |
| 39 |
| 40 // Returns SetupFlowStep object that corresponds to the next |
| 41 // step. Must never return NULL. |
| 42 virtual SetupFlowStep* GetNextStep() = 0; |
| 43 |
| 44 private: |
| 45 DISALLOW_COPY_AND_ASSIGN(SetupFlowStep); |
| 46 }; |
| 47 |
| 48 // SetupFlowStepBase implements base functions common for all |
| 49 // SetupFlowStep implementations. |
| 50 class SetupFlowStepBase : public SetupFlowStep { |
| 51 public: |
| 52 SetupFlowStepBase(); |
| 53 ~SetupFlowStepBase(); |
| 54 |
| 55 // SetupFlowStep implementation. |
| 56 virtual void Start(SetupFlow* flow, DoneCallback* done_callback); |
| 57 virtual SetupFlowStep* GetNextStep(); |
| 58 |
| 59 protected: |
| 60 SetupFlow* flow() { return flow_; } |
| 61 |
| 62 void ExecuteJavascriptInIFrame(const std::wstring& iframe_xpath, |
| 63 const std::wstring& js); |
| 64 |
| 65 // Finish current step. Calls |done_callback| specified in Start(). |
| 66 // GetNextStep() will return the specified |next_step|. |
| 67 void FinishStep(SetupFlowStep* next_step); |
| 68 |
| 69 // Called from Start(). Child classes must override this method |
| 70 // instead of Start(). |
| 71 virtual void DoStart() = 0; |
| 72 |
| 73 private: |
| 74 SetupFlow* flow_; |
| 75 scoped_ptr<DoneCallback> done_callback_; |
| 76 bool done_; |
| 77 |
| 78 // Next step stored between Done() and GetNextStep(); |
| 79 SetupFlowStep* next_step_; |
| 80 |
| 81 DISALLOW_COPY_AND_ASSIGN(SetupFlowStepBase); |
| 82 }; |
| 83 |
| 84 // The last step in the setup flow. This step never finishes, user is |
| 85 // expected to close dialog after that. |
| 86 class SetupFlowDoneStep : public SetupFlowStepBase { |
| 87 public: |
| 88 SetupFlowDoneStep(); |
| 89 virtual ~SetupFlowDoneStep(); |
| 90 |
| 91 // SetupFlowStep implementation. |
| 92 virtual void HandleMessage(const std::string& message, const ListValue* args); |
| 93 virtual void Cancel(); |
| 94 |
| 95 protected: |
| 96 void DoStart(); |
| 97 |
| 98 private: |
| 99 DISALLOW_COPY_AND_ASSIGN(SetupFlowDoneStep); |
| 100 }; |
| 101 |
| 102 // This class is responsible for showing a remoting setup dialog and |
| 103 // perform operations to fill the content of the dialog and handle |
| 104 // user actions in the dialog. |
| 105 class SetupFlow : public DOMMessageHandler, |
| 106 public HtmlDialogUIDelegate { |
| 107 public: |
| 108 virtual ~SetupFlow(); |
| 109 |
| 110 static SetupFlow* OpenSetupDialog(Profile* profile); |
| 111 |
| 112 DOMUI* dom_ui() { return dom_ui_; } |
| 113 Profile* profile() { return profile_; } |
| 114 |
| 115 private: |
| 116 explicit SetupFlow(const std::string& args, Profile* profile, |
| 117 SetupFlowStep* first_step); |
| 118 |
| 119 // HtmlDialogUIDelegate implementation. |
| 120 virtual GURL GetDialogContentURL() const; |
| 121 virtual void GetDOMMessageHandlers( |
| 122 std::vector<DOMMessageHandler*>* handlers) const; |
| 123 virtual void GetDialogSize(gfx::Size* size) const; |
| 124 virtual std::string GetDialogArgs() const; |
| 125 virtual void OnDialogClosed(const std::string& json_retval); |
| 126 virtual void OnCloseContents(TabContents* source, bool* out_close_dialog); |
| 127 virtual std::wstring GetDialogTitle() const; |
| 128 virtual bool IsDialogModal() const; |
| 129 virtual bool ShouldShowDialogTitle() const; |
| 130 |
| 131 // DOMMessageHandler implementation. |
| 132 virtual DOMMessageHandler* Attach(DOMUI* dom_ui); |
| 133 virtual void RegisterMessages(); |
| 134 |
| 135 void HandleSubmitAuth(const ListValue* args); |
| 136 |
| 137 void StartCurrentStep(); |
| 138 void OnStepDone(); |
| 139 |
| 140 // Pointer to the DOM UI. This is provided by RemotingSetupMessageHandler |
| 141 // when attached. |
| 142 DOMUI* dom_ui_; |
| 143 |
| 144 // The args to pass to the initial page. |
| 145 std::string dialog_start_args_; |
| 146 Profile* profile_; |
| 147 |
| 148 scoped_ptr<SetupFlowStep> current_step_; |
| 149 |
| 150 DISALLOW_COPY_AND_ASSIGN(SetupFlow); |
| 151 }; |
| 152 |
| 153 } // namespace remoting |
| 154 |
| 155 #endif // CHROME_BROWSER_REMOTING_SETUP_FLOW_H_ |
OLD | NEW |