widget/windows/winrt/FrameworkView.h

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #pragma once
michael@0 7
michael@0 8 #include "MetroWidget.h"
michael@0 9 #include "MetroInput.h"
michael@0 10 #include "gfxWindowsPlatform.h"
michael@0 11 #include "nsDataHashtable.h"
michael@0 12
michael@0 13 #include "mozwrlbase.h"
michael@0 14
michael@0 15 #include <windows.system.h>
michael@0 16 #include <Windows.ApplicationModel.core.h>
michael@0 17 #include <Windows.ApplicationModel.h>
michael@0 18 #include <Windows.Applicationmodel.Activation.h>
michael@0 19 #include <Windows.ApplicationModel.search.h>
michael@0 20 #include <windows.ui.core.h>
michael@0 21 #include <windows.ui.viewmanagement.h>
michael@0 22 #include <windows.ui.applicationsettings.h>
michael@0 23 #include <windows.ui.popups.h>
michael@0 24 #include <windows.graphics.printing.h>
michael@0 25 #include <windows.graphics.display.h>
michael@0 26 #include <windows.media.playto.h>
michael@0 27 #include <d2d1_1.h>
michael@0 28
michael@0 29 namespace mozilla {
michael@0 30 namespace widget {
michael@0 31 namespace winrt {
michael@0 32
michael@0 33 class MetroApp;
michael@0 34
michael@0 35 class FrameworkView : public Microsoft::WRL::RuntimeClass<ABI::Windows::ApplicationModel::Core::IFrameworkView>
michael@0 36 {
michael@0 37 InspectableClass(L"FrameworkView", TrustLevel::BaseTrust)
michael@0 38
michael@0 39 typedef mozilla::layers::LayerManager LayerManager;
michael@0 40
michael@0 41 typedef ABI::Windows::Foundation::Rect Rect;
michael@0 42 typedef ABI::Windows::UI::Core::IWindowSizeChangedEventArgs IWindowSizeChangedEventArgs;
michael@0 43 typedef ABI::Windows::UI::Core::ICoreWindowEventArgs ICoreWindowEventArgs;
michael@0 44 typedef ABI::Windows::UI::Core::IWindowActivatedEventArgs IWindowActivatedEventArgs;
michael@0 45 typedef ABI::Windows::UI::Core::IAutomationProviderRequestedEventArgs IAutomationProviderRequestedEventArgs;
michael@0 46 typedef ABI::Windows::UI::Core::ICoreWindow ICoreWindow;
michael@0 47 typedef ABI::Windows::UI::Core::ICoreDispatcher ICoreDispatcher;
michael@0 48 typedef ABI::Windows::UI::Core::IVisibilityChangedEventArgs IVisibilityChangedEventArgs;
michael@0 49 typedef ABI::Windows::UI::ViewManagement::IInputPaneVisibilityEventArgs IInputPaneVisibilityEventArgs;
michael@0 50 typedef ABI::Windows::UI::ViewManagement::IInputPane IInputPane;
michael@0 51 typedef ABI::Windows::UI::ViewManagement::ApplicationViewState ApplicationViewState;
michael@0 52 typedef ABI::Windows::UI::ApplicationSettings::ISettingsPane ISettingsPane;
michael@0 53 typedef ABI::Windows::UI::ApplicationSettings::ISettingsPaneCommandsRequestedEventArgs ISettingsPaneCommandsRequestedEventArgs;
michael@0 54 typedef ABI::Windows::UI::Popups::IUICommand IUICommand;
michael@0 55 typedef ABI::Windows::ApplicationModel::Activation::ILaunchActivatedEventArgs ILaunchActivatedEventArgs;
michael@0 56 typedef ABI::Windows::ApplicationModel::Activation::IActivatedEventArgs IActivatedEventArgs;
michael@0 57 typedef ABI::Windows::ApplicationModel::Activation::ISearchActivatedEventArgs ISearchActivatedEventArgs;
michael@0 58 typedef ABI::Windows::ApplicationModel::Activation::IFileActivatedEventArgs IFileActivatedEventArgs;
michael@0 59 typedef ABI::Windows::ApplicationModel::Core::ICoreApplicationView ICoreApplicationView;
michael@0 60 typedef ABI::Windows::ApplicationModel::DataTransfer::IDataTransferManager IDataTransferManager;
michael@0 61 typedef ABI::Windows::ApplicationModel::DataTransfer::IDataRequestedEventArgs IDataRequestedEventArgs;
michael@0 62 typedef ABI::Windows::ApplicationModel::Search::ISearchPane ISearchPane;
michael@0 63 typedef ABI::Windows::ApplicationModel::Search::ISearchPaneQuerySubmittedEventArgs ISearchPaneQuerySubmittedEventArgs;
michael@0 64 typedef ABI::Windows::Media::PlayTo::IPlayToManager IPlayToManager;
michael@0 65 typedef ABI::Windows::Media::PlayTo::IPlayToSourceRequestedEventArgs IPlayToSourceRequestedEventArgs;
michael@0 66 typedef ABI::Windows::Graphics::Printing::IPrintManager IPrintManager;
michael@0 67 typedef ABI::Windows::Graphics::Printing::IPrintTaskRequestedEventArgs IPrintTaskRequestedEventArgs;
michael@0 68 typedef ABI::Windows::Graphics::Printing::IPrintTaskSourceRequestedArgs IPrintTaskSourceRequestedArgs;
michael@0 69
michael@0 70 public:
michael@0 71 FrameworkView(MetroApp* aMetroApp);
michael@0 72
michael@0 73 // IFrameworkView Methods
michael@0 74 STDMETHODIMP Initialize(ICoreApplicationView* aAppView);
michael@0 75 STDMETHODIMP SetWindow(ICoreWindow* aWindow);
michael@0 76 STDMETHODIMP Load(HSTRING aEntryPoint);
michael@0 77 STDMETHODIMP Run();
michael@0 78 STDMETHODIMP Uninitialize();
michael@0 79
michael@0 80 HRESULT ActivateView();
michael@0 81
michael@0 82 // Public apis for MetroWidget
michael@0 83 float GetDPI() { return mDPI; }
michael@0 84 ICoreWindow* GetCoreWindow() { return mWindow.Get(); }
michael@0 85 void SetWidget(MetroWidget* aWidget);
michael@0 86 MetroWidget* GetWidget() { return mWidget.Get(); }
michael@0 87 void GetBounds(nsIntRect &aRect);
michael@0 88 void SetCursor(ABI::Windows::UI::Core::CoreCursorType aCursorType, DWORD aCustomId = 0);
michael@0 89 void ClearCursor();
michael@0 90 bool IsEnabled() const;
michael@0 91 bool IsVisible() const;
michael@0 92
michael@0 93 // Activation apis for nsIWinMetroUtils
michael@0 94 static int GetPreviousExecutionState() { return sPreviousExecutionState; }
michael@0 95 static void GetActivationURI(nsAString &aActivationURI) {
michael@0 96 unsigned int length;
michael@0 97 aActivationURI = WindowsGetStringRawBuffer(sActivationURI, &length);
michael@0 98 }
michael@0 99
michael@0 100 // Soft keyboard info for nsIWinMetroUtils
michael@0 101 static bool IsKeyboardVisible() { return sKeyboardIsVisible; }
michael@0 102 static ABI::Windows::Foundation::Rect KeyboardVisibleRect() { return sKeyboardRect; }
michael@0 103
michael@0 104 // MetroApp apis
michael@0 105 void SetupContracts();
michael@0 106 void Shutdown();
michael@0 107
michael@0 108 // MetroContracts settings panel enumerator entry
michael@0 109 void AddSetting(ISettingsPaneCommandsRequestedEventArgs* aArgs, uint32_t aId,
michael@0 110 Microsoft::WRL::Wrappers::HString& aSettingName);
michael@0 111 protected:
michael@0 112 // Event Handlers
michael@0 113 HRESULT OnActivated(ICoreApplicationView* aApplicationView,
michael@0 114 IActivatedEventArgs* aArgs);
michael@0 115 HRESULT OnWindowVisibilityChanged(ICoreWindow* aCoreWindow,
michael@0 116 IVisibilityChangedEventArgs* aArgs);
michael@0 117
michael@0 118 HRESULT OnWindowSizeChanged(ICoreWindow* aSender,
michael@0 119 IWindowSizeChangedEventArgs* aArgs);
michael@0 120 HRESULT OnWindowActivated(ICoreWindow* aSender,
michael@0 121 IWindowActivatedEventArgs* aArgs);
michael@0 122 HRESULT OnLogicalDpiChanged(IInspectable* aSender);
michael@0 123
michael@0 124 HRESULT OnAutomationProviderRequested(ICoreWindow* aSender,
michael@0 125 IAutomationProviderRequestedEventArgs* aArgs);
michael@0 126
michael@0 127 HRESULT OnSoftkeyboardHidden(IInputPane* aSender,
michael@0 128 IInputPaneVisibilityEventArgs* aArgs);
michael@0 129 HRESULT OnSoftkeyboardShown(IInputPane* aSender,
michael@0 130 IInputPaneVisibilityEventArgs* aArgs);
michael@0 131
michael@0 132 HRESULT OnDataShareRequested(IDataTransferManager*, IDataRequestedEventArgs* aArgs);
michael@0 133 HRESULT OnSearchQuerySubmitted(ISearchPane* aPane, ISearchPaneQuerySubmittedEventArgs* aArgs);
michael@0 134 HRESULT OnSettingsCommandsRequested(ISettingsPane* aPane, ISettingsPaneCommandsRequestedEventArgs* aArgs);
michael@0 135 HRESULT OnPlayToSourceRequested(IPlayToManager* aPane, IPlayToSourceRequestedEventArgs* aArgs);
michael@0 136 HRESULT OnSettingsCommandInvoked(IUICommand* aCommand);
michael@0 137 HRESULT OnPrintTaskRequested(IPrintManager* aMgr, IPrintTaskRequestedEventArgs* aArgs);
michael@0 138 HRESULT OnPrintTaskSourceRequested(IPrintTaskSourceRequestedArgs* aArgs);
michael@0 139
michael@0 140 protected:
michael@0 141 void SetDpi(float aDpi);
michael@0 142 void UpdateWidgetSizeAndPosition();
michael@0 143 void PerformURILoad(Microsoft::WRL::Wrappers::HString& aString);
michael@0 144 void PerformSearch(Microsoft::WRL::Wrappers::HString& aQuery);
michael@0 145 void PerformURILoadOrSearch(Microsoft::WRL::Wrappers::HString& aString);
michael@0 146 bool EnsureAutomationProviderCreated();
michael@0 147 void SearchActivated(Microsoft::WRL::ComPtr<ISearchActivatedEventArgs>& aArgs, bool aStartup);
michael@0 148 void FileActivated(Microsoft::WRL::ComPtr<IFileActivatedEventArgs>& aArgs, bool aStartup);
michael@0 149 void LaunchActivated(Microsoft::WRL::ComPtr<ILaunchActivatedEventArgs>& aArgs, bool aStartup);
michael@0 150 void ProcessActivationArgs(IActivatedEventArgs* aArgs, bool aStartup);
michael@0 151 void UpdateForWindowSizeChange();
michael@0 152 void SendActivationEvent();
michael@0 153 void UpdateLogicalDPI();
michael@0 154 void FireViewStateObservers();
michael@0 155 void ProcessLaunchArguments();
michael@0 156 void UpdateBounds();
michael@0 157
michael@0 158 // Printing and preview
michael@0 159 void CreatePrintControl(IPrintDocumentPackageTarget* aDocPackageTarget,
michael@0 160 D2D1_PRINT_CONTROL_PROPERTIES* aPrintControlProperties);
michael@0 161 HRESULT ClosePrintControl();
michael@0 162 void PrintPage(uint32_t aPageNumber, D2D1_RECT_F aImageableArea,
michael@0 163 D2D1_SIZE_F aPageSize, IStream* aPagePrintTicketStream);
michael@0 164 void AddEventHandlers();
michael@0 165
michael@0 166 private:
michael@0 167 EventRegistrationToken mActivated;
michael@0 168 EventRegistrationToken mWindowActivated;
michael@0 169 EventRegistrationToken mWindowVisibilityChanged;
michael@0 170 EventRegistrationToken mWindowClosed;
michael@0 171 EventRegistrationToken mWindowSizeChanged;
michael@0 172 EventRegistrationToken mSoftKeyboardHidden;
michael@0 173 EventRegistrationToken mSoftKeyboardShown;
michael@0 174 EventRegistrationToken mDisplayPropertiesChanged;
michael@0 175 EventRegistrationToken mAutomationProviderRequested;
michael@0 176 EventRegistrationToken mDataTransferRequested;
michael@0 177 EventRegistrationToken mSearchQuerySubmitted;
michael@0 178 EventRegistrationToken mPlayToRequested;
michael@0 179 EventRegistrationToken mSettingsPane;
michael@0 180 EventRegistrationToken mPrintManager;
michael@0 181
michael@0 182 private:
michael@0 183 nsIntRect mWindowBounds; // in device-pixel coordinates
michael@0 184 float mDPI;
michael@0 185 bool mShuttingDown;
michael@0 186 nsAutoString mActivationCommandLine;
michael@0 187 Microsoft::WRL::ComPtr<IInspectable> mAutomationProvider;
michael@0 188 //Microsoft::WRL::ComPtr<ID2D1PrintControl> mD2DPrintControl;
michael@0 189 // Private critical section protects D2D device context for on-screen
michael@0 190 // rendering from that for print/preview in the different thread.
michael@0 191 //Microsoft::WRL::ComPtr<IWICImagingFactory2> mWicFactory;
michael@0 192 Microsoft::WRL::ComPtr<MetroApp> mMetroApp;
michael@0 193 Microsoft::WRL::ComPtr<ICoreWindow> mWindow;
michael@0 194 Microsoft::WRL::ComPtr<MetroWidget> mWidget;
michael@0 195 Microsoft::WRL::ComPtr<MetroInput> mMetroInput;
michael@0 196 bool mWinVisible;
michael@0 197 bool mWinActiveState;
michael@0 198
michael@0 199 static bool sKeyboardIsVisible;
michael@0 200 static Rect sKeyboardRect;
michael@0 201 static HSTRING sActivationURI;
michael@0 202 static ABI::Windows::ApplicationModel::Activation::ApplicationExecutionState sPreviousExecutionState;
michael@0 203 };
michael@0 204
michael@0 205 } } }

mercurial