| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e3d50a5 commit 2e9cb3d
11 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,10 +5,7 @@ | |||
| 5 | 5 | # If you try to keep PyBrowser() objects inside c_vector you will get segmentation | |
| 6 | 6 | # faults, as they will be garbage collected. | |
| 7 | 7 | ||
| 8 | - cdef list g_pyBrowsers = [] | ||
| 9 | - | ||
| 10 | - # TODO: remove: | ||
| 11 | - # Debug("DisplayHandler_OnTitleChange(): cdef pyBrowser: %s" % pyBrowser) | ||
| 8 | + cdef dict g_pyBrowsers = {} | ||
| 12 | 9 | ||
| 13 | 10 | cdef PyBrowser GetPyBrowser(CefRefPtr[CefBrowser] cefBrowser): | |
| 14 | 11 | ||
@@ -17,39 +14,40 @@ cdef PyBrowser GetPyBrowser(CefRefPtr[CefBrowser] cefBrowser): | |||
| 17 | 14 | if <void*>cefBrowser == NULL or not cefBrowser.get(): | |
| 18 | 15 | Debug("GetPyBrowser(): returning None") | |
| 19 | 16 | return None | |
| 20 | - | ||
| 17 | + | ||
| 21 | 18 | cdef PyBrowser pyBrowser | |
| 22 | - cdef CefWindowHandle windowHandle1 | ||
| 23 | - cdef CefWindowHandle windowHandle2 | ||
| 19 | + cdef int browserId | ||
| 24 | 20 | ||
| 25 | - for pyBrowser in g_pyBrowsers: | ||
| 26 | - if pyBrowser.cefBrowser.get(): | ||
| 27 | - if pyBrowser.cefBrowser.get().GetIdentifier() == cefBrowser.get().GetIdentifier(): | ||
| 28 | - return pyBrowser | ||
| 29 | - else: | ||
| 30 | - Debug("GetPyBrowser(): removing an empty reference from g_pyBrowsers") | ||
| 31 | - # TODO. | ||
| 21 | + browserId = cefBrowser.get().GetIdentifier() | ||
| 22 | + if browserId in g_pyBrowsers: | ||
| 23 | + return g_pyBrowsers[browserId] | ||
| 32 | 24 | ||
| 33 | - Debug("GetPyBrowser(): creating new PyBrowser") | ||
| 25 | + for id, pyBrowser in g_pyBrowsers.items(): | ||
| 26 | + if not pyBrowser.cefBrowser.get(): | ||
| 27 | + Debug("GetPyBrowser(): removing an empty CefBrowser reference, browserId=%s" % id) | ||
| 28 | + del g_pyBrowsers[id] | ||
| 29 | + | ||
| 30 | + Debug("GetPyBrowser(): creating new PyBrowser, browserId=%s" % browserId) | ||
| 34 | 31 | pyBrowser = PyBrowser() | |
| 35 | 32 | pyBrowser.cefBrowser = cefBrowser | |
| 36 | - g_pyBrowsers.append(pyBrowser) | ||
| 33 | + g_pyBrowsers[browserId] = pyBrowser | ||
| 37 | 34 | return pyBrowser | |
| 38 | 35 | ||
| 39 | 36 | cpdef PyBrowser GetBrowserByWindowHandle(int windowHandle): | |
| 40 | 37 | ||
| 41 | 38 | cdef PyBrowser pyBrowser | |
| 42 | - for pyBrowser in g_pyBrowsers: | ||
| 43 | - if (pyBrowser.GetWindowHandle() == windowHandle or | ||
| 39 | + for browserId in g_pyBrowsers: | ||
| 40 | + pyBrowser = g_pyBrowsers[browserId] | ||
| 41 | + if (pyBrowser.GetWindowHandle() == windowHandle or | ||
| 44 | 42 | pyBrowser.GetUserData("__outerWindowHandle") == windowHandle): | |
| 45 | 43 | return pyBrowser | |
| 46 | 44 | return None | |
| 47 | 45 | ||
| 48 | 46 | IF CEF_VERSION == 3: | |
| 49 | - | ||
| 47 | + | ||
| 50 | 48 | cdef CefRefPtr[CefBrowserHost] GetCefBrowserHost( | |
| 51 | 49 | CefRefPtr[CefBrowser] cefBrowser) except *: | |
| 52 | - | ||
| 50 | + | ||
| 53 | 51 | cdef CefRefPtr[CefBrowserHost] cefBrowserHost = cefBrowser.get().GetHost() | |
| 54 | 52 | if <void*>cefBrowserHost != NULL and cefBrowserHost.get(): | |
| 55 | 53 | return cefBrowserHost | |
@@ -65,7 +63,7 @@ cdef class PyBrowser: | |||
| 65 | 63 | IF CEF_VERSION == 1: | |
| 66 | 64 | cdef public JavascriptBindings javascriptBindings | |
| 67 | 65 | cdef public dict userData | |
| 68 | - | ||
| 66 | + | ||
| 69 | 67 | # Properties used by ToggleFullscreen(). | |
| 70 | 68 | cdef public int isFullscreen | |
| 71 | 69 | cdef public int maximized | |
@@ -82,57 +80,57 @@ cdef class PyBrowser: | |||
| 82 | 80 | IF CEF_VERSION == 3: | |
| 83 | 81 | ||
| 84 | 82 | cdef CefRefPtr[CefBrowserHost] GetCefBrowserHost(self) except *: | |
| 85 | - | ||
| 83 | + | ||
| 86 | 84 | cdef CefRefPtr[CefBrowserHost] cefBrowserHost = self.GetCefBrowser().get().GetHost() | |
| 87 | 85 | if <void*>cefBrowserHost != NULL and cefBrowserHost.get(): | |
| 88 | 86 | return cefBrowserHost | |
| 89 | 87 | raise Exception("PyBrowser.GetCefBrowserHost() failed: this method " | |
| 90 | 88 | "can only be called in the browser process.") | |
| 91 | - | ||
| 89 | + | ||
| 92 | 90 | def __init__(self): | |
| 93 | 91 | ||
| 94 | 92 | self.clientCallbacks = {} | |
| 95 | 93 | self.allowedClientCallbacks = [] | |
| 96 | 94 | self.userData = {} | |
| 97 | 95 | ||
| 98 | - cpdef object SetClientCallback(self, str name, object callback): | ||
| 96 | + cpdef py_void SetClientCallback(self, py_string name, object callback): | ||
| 99 | 97 | ||
| 100 | 98 | if not self.allowedClientCallbacks: | |
| 101 | - | ||
| 99 | + | ||
| 102 | 100 | # CefLoadHandler. | |
| 103 | 101 | self.allowedClientCallbacks += ["OnLoadEnd", "OnLoadError", "OnLoadStart"] | |
| 104 | - | ||
| 102 | + | ||
| 105 | 103 | # CefKeyboardHandler. | |
| 106 | 104 | self.allowedClientCallbacks += ["OnKeyEvent"] | |
| 107 | - | ||
| 105 | + | ||
| 108 | 106 | # CefV8ContextHandler. | |
| 109 | 107 | self.allowedClientCallbacks += ["OnUncaughtException"] | |
| 110 | - | ||
| 108 | + | ||
| 111 | 109 | # CefRequestHandler. | |
| 112 | - self.allowedClientCallbacks += ["OnBeforeBrowse", "OnBeforeResourceLoad", | ||
| 113 | - "OnResourceRedirect", "OnResourceResponse", "OnProtocolExecution", | ||
| 110 | + self.allowedClientCallbacks += ["OnBeforeBrowse", "OnBeforeResourceLoad", | ||
| 111 | + "OnResourceRedirect", "OnResourceResponse", "OnProtocolExecution", | ||
| 114 | 112 | "GetDownloadHandler", "GetAuthCredentials", "GetCookieManager"] | |
| 115 | - | ||
| 113 | + | ||
| 116 | 114 | # CefDisplayHandler. | |
| 117 | - self.allowedClientCallbacks += ["OnAddressChange", "OnConsoleMessage", | ||
| 118 | - "OnContentsSizeChange", "OnNavStateChange", "OnStatusMessage", | ||
| 115 | + self.allowedClientCallbacks += ["OnAddressChange", "OnConsoleMessage", | ||
| 116 | + "OnContentsSizeChange", "OnNavStateChange", "OnStatusMessage", | ||
| 119 | 117 | "OnTitleChange", "OnTooltip"] | |
| 120 | - | ||
| 118 | + | ||
| 121 | 119 | # LifespanHandler. | |
| 122 | 120 | self.allowedClientCallbacks += ["DoClose", "OnAfterCreated", "OnBeforeClose", | |
| 123 | 121 | "RunModal"] | |
| 124 | 122 | ||
| 125 | 123 | if name not in self.allowedClientCallbacks: | |
| 126 | 124 | raise Exception("Browser.SetClientCallback() failed: unknown callback: %s" % name) | |
| 127 | - | ||
| 125 | + | ||
| 128 | 126 | self.clientCallbacks[name] = callback | |
| 129 | - | ||
| 130 | - cpdef object SetClientHandler(self, object clientHandler): | ||
| 131 | - | ||
| 127 | + | ||
| 128 | + cpdef py_void SetClientHandler(self, object clientHandler): | ||
| 129 | + | ||
| 132 | 130 | if not hasattr(clientHandler, "__class__"): | |
| 133 | 131 | raise Exception("Browser.SetClientHandler() failed: __class__ attribute missing") | |
| 134 | 132 | cdef dict methods = {} | |
| 135 | - cdef str key | ||
| 133 | + cdef py_string key | ||
| 136 | 134 | cdef object method | |
| 137 | 135 | cdef tuple value | |
| 138 | 136 | for value in inspect.getmembers(clientHandler, predicate=inspect.ismethod): | |
@@ -141,7 +139,7 @@ cdef class PyBrowser: | |||
| 141 | 139 | if key and key[0] != '_': | |
| 142 | 140 | self.SetClientCallback(key, method) | |
| 143 | 141 | ||
| 144 | - cpdef object GetClientCallback(self, str name): | ||
| 142 | + cpdef object GetClientCallback(self, py_string name): | ||
| 145 | 143 | ||
| 146 | 144 | if name in self.clientCallbacks: | |
| 147 | 145 | return self.clientCallbacks[name] | |
@@ -152,7 +150,7 @@ cdef class PyBrowser: | |||
| 152 | 150 | ||
| 153 | 151 | IF CEF_VERSION == 1: | |
| 154 | 152 | ||
| 155 | - cpdef object SetJavascriptBindings(self, JavascriptBindings bindings): | ||
| 153 | + cpdef py_void SetJavascriptBindings(self, JavascriptBindings bindings): | ||
| 156 | 154 | ||
| 157 | 155 | self.javascriptBindings = bindings | |
| 158 | 156 | ||
@@ -178,15 +176,15 @@ cdef class PyBrowser: | |||
| 178 | 176 | ||
| 179 | 177 | self.GetCefBrowser().get().ClearHistory() | |
| 180 | 178 | ||
| 181 | - cpdef object CloseBrowser(self): | ||
| 179 | + cpdef py_void CloseBrowser(self): | ||
| 182 | 180 | ||
| 183 | 181 | # In cefclient/cefclient_win.cpp there is only ParentWindowWillClose() called. | |
| 184 | 182 | # CloseBrowser() is called only for popups. | |
| 185 | 183 | ||
| 186 | 184 | if self.GetUserData("__outerWindowHandle"): | |
| 187 | 185 | IF CEF_VERSION == 1: | |
| 188 | - Debug("CefBrowser::ParentWindowWillClose()") | ||
| 189 | - self.GetCefBrowser().get().ParentWindowWillClose() | ||
| 186 | + Debug("CefBrowser::ParentWindowWillClose()") | ||
| 187 | + self.GetCefBrowser().get().ParentWindowWillClose() | ||
| 190 | 188 | ELIF CEF_VERSION == 3: | |
| 191 | 189 | Debug("CefBrowserHost::ParentWindowWillClose()") | |
| 192 | 190 | self.GetCefBrowserHost().get().ParentWindowWillClose() | |
@@ -200,11 +198,11 @@ cdef class PyBrowser: | |||
| 200 | 198 | ||
| 201 | 199 | IF CEF_VERSION == 1: | |
| 202 | 200 | ||
| 203 | - cpdef object CloseDevTools(self): | ||
| 204 | - | ||
| 201 | + cpdef py_void CloseDevTools(self): | ||
| 202 | + | ||
| 205 | 203 | self.GetCefBrowser().get().CloseDevTools() | |
| 206 | 204 | ||
| 207 | - cpdef object Find(self, int searchId, str searchText, py_bool forward, | ||
| 205 | + cpdef py_void Find(self, int searchId, py_string searchText, py_bool forward, | ||
| 208 | 206 | py_bool matchCase, py_bool findNext): | |
| 209 | 207 | ||
| 210 | 208 | cdef CefString cefSearchText | |
@@ -217,7 +215,7 @@ cdef class PyBrowser: | |||
| 217 | 215 | assert IsCurrentThread(TID_UI), "Browser.GetFocusedFrame() may only be called on the UI thread" | |
| 218 | 216 | return GetPyFrame(self.GetCefBrowser().get().GetFocusedFrame()) | |
| 219 | 217 | ||
| 220 | - cpdef PyFrame GetFrame(self, str name): | ||
| 218 | + cpdef PyFrame GetFrame(self, py_string name): | ||
| 221 | 219 | ||
| 222 | 220 | assert IsCurrentThread(TID_UI), "Browser.GetFrame() may only be called on the UI thread" | |
| 223 | 221 | cdef CefString cefName | |
@@ -242,7 +240,7 @@ cdef class PyBrowser: | |||
| 242 | 240 | ||
| 243 | 241 | return GetPyFrame(self.GetCefBrowser().get().GetMainFrame()) | |
| 244 | 242 | ||
| 245 | - def GetOpenerWindowHandle(self): | ||
| 243 | + cpdef int GetOpenerWindowHandle(self) except *: | ||
| 246 | 244 | ||
| 247 | 245 | cdef HWND hwnd | |
| 248 | 246 | IF CEF_VERSION == 1: | |
@@ -251,20 +249,20 @@ cdef class PyBrowser: | |||
| 251 | 249 | hwnd = self.GetCefBrowserHost().get().GetOpenerWindowHandle() | |
| 252 | 250 | return <int>hwnd | |
| 253 | 251 | ||
| 254 | - def GetOuterWindowHandle(self): | ||
| 252 | + cpdef int GetOuterWindowHandle(self) except *: | ||
| 255 | 253 | ||
| 256 | 254 | if self.GetUserData("__outerWindowHandle"): | |
| 257 | - return self.GetUserData("__outerWindowHandle") | ||
| 255 | + return int(self.GetUserData("__outerWindowHandle")) | ||
| 258 | 256 | else: | |
| 259 | 257 | return self.GetWindowHandle() | |
| 260 | 258 | ||
| 261 | - def GetUserData(self, key): | ||
| 259 | + cpdef object GetUserData(self, object key): | ||
| 262 | 260 | ||
| 263 | 261 | if key in self.userData: | |
| 264 | 262 | return self.userData[key] | |
| 265 | 263 | return None | |
| 266 | 264 | ||
| 267 | - def GetWindowHandle(self): | ||
| 265 | + cpdef int GetWindowHandle(self) except *: | ||
| 268 | 266 | ||
| 269 | 267 | cdef HWND hwnd | |
| 270 | 268 | IF CEF_VERSION == 1: | |
@@ -273,7 +271,7 @@ cdef class PyBrowser: | |||
| 273 | 271 | hwnd = self.GetCefBrowserHost().get().GetWindowHandle() | |
| 274 | 272 | return <int>hwnd | |
| 275 | 273 | ||
| 276 | - def GetZoomLevel(self): | ||
| 274 | + cpdef double GetZoomLevel(self) except *: | ||
| 277 | 275 | ||
| 278 | 276 | IF CEF_VERSION == 1: | |
| 279 | 277 | assert IsCurrentThread(TID_UI), "Browser.GetZoomLevel() may only be called on the UI thread" | |
@@ -284,97 +282,98 @@ cdef class PyBrowser: | |||
| 284 | 282 | zoomLevel = self.GetCefBrowserHost().get().GetZoomLevel() | |
| 285 | 283 | return zoomLevel | |
| 286 | 284 | ||
| 287 | - def GoBack(self): | ||
| 285 | + cpdef py_void GoBack(self): | ||
| 288 | 286 | ||
| 289 | 287 | self.GetCefBrowser().get().GoBack() | |
| 290 | 288 | ||
| 291 | - def GoForward(self): | ||
| 289 | + cpdef py_void GoForward(self): | ||
| 292 | 290 | ||
| 293 | 291 | self.GetCefBrowser().get().GoForward() | |
| 294 | 292 | ||
| 295 | - def HasDocument(self): | ||
| 293 | + cpdef py_bool HasDocument(self): | ||
| 296 | 294 | ||
| 297 | 295 | return self.GetCefBrowser().get().HasDocument() | |
| 298 | 296 | ||
| 299 | 297 | IF CEF_VERSION == 1: | |
| 300 | 298 | ||
| 301 | - def HidePopup(self): | ||
| 299 | + cpdef py_void HidePopup(self): | ||
| 302 | 300 | ||
| 303 | 301 | self.GetCefBrowser().get().HidePopup() | |
| 304 | 302 | ||
| 305 | - def IsFullscreen(self): | ||
| 303 | + cpdef py_bool IsFullscreen(self): | ||
| 306 | 304 | ||
| 307 | 305 | return bool(self.isFullscreen) | |
| 308 | 306 | ||
| 309 | - def IsPopup(self): | ||
| 307 | + cpdef py_bool IsPopup(self): | ||
| 310 | 308 | ||
| 311 | 309 | return self.GetCefBrowser().get().IsPopup() | |
| 312 | 310 | ||
| 313 | 311 | IF CEF_VERSION == 1: | |
| 314 | 312 | ||
| 315 | - def IsPopupVisible(self): | ||
| 313 | + cpdef py_bool IsPopupVisible(self): | ||
| 316 | 314 | ||
| 317 | 315 | assert IsCurrentThread(TID_UI), "Browser.IsPopupVisible() may only be called on the UI thread" | |
| 318 | 316 | return self.GetCefBrowser().get().IsPopupVisible() | |
| 319 | 317 | ||
| 320 | - def IsWindowRenderingDisabled(self): | ||
| 318 | + cpdef py_bool IsWindowRenderingDisabled(self): | ||
| 321 | 319 | ||
| 322 | 320 | return self.GetCefBrowser().get().IsWindowRenderingDisabled() | |
| 323 | 321 | ||
| 324 | - def Reload(self): | ||
| 322 | + cpdef py_void Reload(self): | ||
| 325 | 323 | ||
| 326 | 324 | self.GetCefBrowser().get().Reload() | |
| 327 | 325 | ||
| 328 | - def ReloadIgnoreCache(self): | ||
| 326 | + cpdef py_void ReloadIgnoreCache(self): | ||
| 329 | 327 | ||
| 330 | 328 | self.GetCefBrowser().get().ReloadIgnoreCache() | |
| 331 | 329 | ||
| 332 | - def SetFocus(self, enable): | ||
| 330 | + cpdef py_void SetFocus(self, enable): | ||
| 333 | 331 | ||
| 334 | 332 | IF CEF_VERSION == 1: | |
| 335 | 333 | self.GetCefBrowser().get().SetFocus(bool(enable)) | |
| 336 | 334 | ELIF CEF_VERSION == 3: | |
| 337 | 335 | self.GetCefBrowserHost().get().SetFocus(bool(enable)) | |
| 338 | 336 | ||
| 339 | - def SetUserData(self, key, value): | ||
| 337 | + cpdef py_void SetUserData(self, object key, object value): | ||
| 340 | 338 | ||
| 341 | 339 | self.userData[key] = value | |
| 342 | 340 | ||
| 343 | - def SetZoomLevel(self, zoomLevel): | ||
| 341 | + cpdef py_void SetZoomLevel(self, double zoomLevel): | ||
| 344 | 342 | ||
| 345 | 343 | IF CEF_VERSION == 1: | |
| 346 | - self.GetCefBrowser().get().SetZoomLevel(<double>float(zoomLevel)) | ||
| 344 | + self.GetCefBrowser().get().SetZoomLevel(zoomLevel) | ||
| 347 | 345 | ELIF CEF_VERSION == 3: | |
| 348 | - self.GetCefBrowserHost().get().SetZoomLevel(<double>float(zoomLevel)) | ||
| 346 | + self.GetCefBrowserHost().get().SetZoomLevel(zoomLevel) | ||
| 349 | 347 | ||
| 350 | 348 | IF CEF_VERSION == 1: | |
| 351 | 349 | ||
| 352 | - def ShowDevTools(self): | ||
| 350 | + cpdef py_void ShowDevTools(self): | ||
| 353 | 351 | ||
| 354 | 352 | self.GetCefBrowser().get().ShowDevTools() | |
| 355 | 353 | ||
| 356 | - def StopLoad(self): | ||
| 354 | + cpdef py_void StopLoad(self): | ||
| 357 | 355 | ||
| 358 | 356 | self.GetCefBrowser().get().StopLoad() | |
| 359 | 357 | ||
| 360 | 358 | IF CEF_VERSION == 1: | |
| 361 | 359 | ||
| 362 | - def StopFinding(self, clearSelection): | ||
| 360 | + cpdef py_void StopFinding(self, py_bool clearSelection): | ||
| 363 | 361 | ||
| 364 | 362 | self.GetCefBrowser().get().StopFinding(bool(clearSelection)) | |
| 365 | 363 | ||
| 366 | - def ToggleFullscreen(self): | ||
| 364 | + cpdef py_void ToggleFullscreen(self): | ||
| 367 | 365 | ||
| 368 | 366 | IF UNAME_SYSNAME == "Windows": | |
| 369 | 367 | ||
| 368 | + cdef int windowHandle | ||
| 370 | 369 | if self.GetUserData("__outerWindowHandle"): | |
| 371 | 370 | windowHandle = self.GetUserData("__outerWindowHandle") | |
| 372 | 371 | else: | |
| 373 | 372 | windowHandle = self.GetWindowHandle() | |
| 374 | - | ||
| 373 | + | ||
| 375 | 374 | # Offscreen browser will have an empty window handle. | |
| 376 | 375 | assert windowHandle, "Browser.ToggleFullscreen() failed: no window handle found" | |
| 377 | - | ||
| 376 | + | ||
| 378 | 377 | cdef HWND hwnd = <HWND><int>int(windowHandle) | |
| 379 | 378 | cdef RECT rect | |
| 380 | 379 | cdef HMONITOR monitor | |
@@ -384,7 +383,7 @@ cdef class PyBrowser: | |||
| 384 | 383 | # Logic copied from chromium > fullscreen_handler.cc > FullscreenHandler::SetFullscreenImpl: | |
| 385 | 384 | # http://src.chromium.org/viewvc/chrome/trunk/src/ui/views/win/fullscreen_handler.cc | |
| 386 | 385 | ||
| 387 | - for_metro = False | ||
| 386 | + cdef py_bool for_metro = False | ||
| 388 | 387 | ||
| 389 | 388 | if not self.isFullscreen: | |
| 390 | 389 | self.maximized = IsZoomed(hwnd) | |
@@ -394,7 +393,10 @@ cdef class PyBrowser: | |||
| 394 | 393 | self.gwlExStyle = GetWindowLong(hwnd, GWL_EXSTYLE) | |
| 395 | 394 | GetWindowRect(hwnd, &rect) | |
| 396 | 395 | self.windowRect = (rect.left, rect.top, rect.right, rect.bottom) | |
| 397 | - | ||
| 396 | + | ||
| 397 | + cdef int remove_style, remove_exstyle | ||
| 398 | + cdef int left, top, right, bottom | ||
| 399 | + | ||
| 398 | 400 | if not self.isFullscreen: | |
| 399 | 401 | remove_style = WS_CAPTION | WS_THICKFRAME | |
| 400 | 402 | remove_exstyle = WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE | |
| Back | FazBrowse Home | New Git URL |
0 commit comments